For questions about Groovy, which is an object-oriented programming language for Java.
Questions tagged [groovy]
42 questions
111
votes
7 answers
Cleanest way to prematurely exit a Jenkins Pipeline job as a success?
I have a job that will create files, unless one of the values being fed to it matches an older value. What's the cleanest way in Jenkins to abort or exit the job, without it being FAILED? It exiting is the correct behavior so I want the build marked…
Alex
- 4,612
- 6
- 29
- 49
7
votes
1 answer
Jenkins Declarative pipeline: Execute stage conditional on execution of previous stage
I have a Jenkins declarative pipeline with several stages. Some of these stages need to be executed based on whether a previous stage has been executed. In pseudocode:
pipeline{
stages{
stage('1: Always do this thing') {
steps {
…
Bruce Becker
- 3,783
- 4
- 20
- 41
5
votes
2 answers
Jenkins Groovy to parse console output and mark build failure
What would be a Groovy or pipeline step to parse Jenkins console output, identify a string and mark the build as failure if the string is matched?
Narasimha
- 89
- 1
- 1
- 8
5
votes
1 answer
Get changes of the parameterized pipeline on the fly in Jenkins
Is it possible to get changes of the parameterized pipeline on the fly after making changes there?
For example I have a pipeline code:
properties([
parameters([
string(name: 'TARGET_HOST', defaultValue: 'test', description:…
user54
- 583
- 1
- 4
- 16
5
votes
2 answers
How to check return status of parallel branches in jenkins pipeline
I am running a Jenkins job on multiple slaves. Following is the code structure:
def branches = [:]
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i < allNodes.size(); i++) {
branches[allNodes[i].name.toString()] = {
…
Anirudh Singh
- 91
- 1
- 6
5
votes
2 answers
Jenkins libraries configuration in Jenkinsfile
Right now we have many projects with similar Jenkinsfile's. Instead of copypasting we're developing a shared library with some utilities. This library is loaded dynamically in each Jenkinsfile, and has some parameters that repeat among calls. For…
Adam
- 151
- 1
- 4
5
votes
3 answers
Jenkins Pipeline downstream job; exit unless it hasn't run in the last x hours
Is there a way in Groovy directly or by integrating Jenkins plugins to have a downstream job complete only if it hasn't been run in the last X hours already?
Let's say I have unit tests, when green, kick off a job to create an image. I want to put…
Alex
- 4,612
- 6
- 29
- 49
4
votes
3 answers
Jenkins UUIDs ... oh the humanity
I have an environment block
environment {
SUITE_RUN_ID = UUID.randomUUID().toString()
SMOKE_CMD = "runtests.sh SUITE_RUN_ID=${SUITE_RUN_ID}"
FAILED_TESTS = "output_rerun_info.rb SUITE_RUN_ID=${SUITE_RUN_ID}"
}
When I use SMOKE_CMD and…
David West
- 1,533
- 3
- 18
- 25
3
votes
0 answers
Jenkins Unable to Match Two Identical Strings
I have a config file that's in YAML format, which includes this relevant portion:
project:
protectedBranches:
- master
- develop
- feature/something
In my Jenkinsfile, the YAML file is loaded via: config = readYaml('config.yml').
I…
Argyle
- 1,026
- 2
- 9
- 20
3
votes
1 answer
Unable to use the class defined in src in vars of jenkins shared library
Here is the folder structure in my shared library repo:
$ tree src vars
src
├── org
└── common.groovy
vars
├── testSrc.groovy
src has:
$ cat src/org/common.groovy
package org.common
class CommonFuncs {
def sayHi() {
echo "Hi from…
rodee
- 187
- 1
- 3
- 8
3
votes
1 answer
It is not allowed to use stages more than once [Jenkins_Declarative_Pipeline]
I am completely new to the jenkins pipeline. I'm trying to create a project with multiple stages but in my Import stage , I want to execute parallel. For each stage in parallel , I have again multiple stages. I'm trying the following way, but…
Auto-learner
- 151
- 4
2
votes
3 answers
How to define global variables in groovy file, which I want to load and consume?
I have a Jenkins parent groovy file which consumes the child groovy file
Parent grooy file:
...
def child = load 'child-groovy-file';
child.execute();
Child groovy file:
a = "first letter";
b = "second letter;
def execute
{
echo "a is…
omkar sirra
- 163
- 1
- 2
- 8
2
votes
1 answer
Groovy script to show only selected item
I used jenkins Active choices plugin and Mavenmetadata plugin to build above UI. When I click a radio button particular version only should be display. How can I write a groovy script to fulfill above requirement?
Below images showing my groovy…
Janith
- 173
- 2
- 7
2
votes
1 answer
How to set a Git repository when creating a job in Jenkins from a Groovy script?
I'm trying to setup a Jenkins server with Groovy script:
def repository = 'git@somerepo'
import hudson.tasks.Shell;
job = Jenkins.instance.createProject(FreeStyleProject, 'TestJob')
job.setDescription("Some description")
job.displayName =…
Alter_so
- 31
- 4
2
votes
1 answer
How to escape dollarsign in groovy shell command?
I'm making a declarative Jenkins pipeline which has a for loop to iterate over the output of a bash command. In that command it is necessary to use bash arguments e.g. "$1" for first argument. And it is a series of pipes with many types of quotes.
I…
kotezbuzzi
- 21
- 1
- 1
- 2