Skip to main content

Questions tagged [groovy]

For questions about Groovy, which is an object-oriented programming language for Java.

Filter by
Sorted by
Tagged with
109 votes
6 answers
288k views

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 ...
Alex's user avatar
  • 4,582
7 votes
1 answer
14k views

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('...
Bruce Becker's user avatar
  • 3,743
5 votes
2 answers
6k views

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++) { ...
Anirudh Singh's user avatar
5 votes
3 answers
6k views

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, ...
Alex's user avatar
  • 4,582
5 votes
2 answers
30k views

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's user avatar
5 votes
2 answers
4k views

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 ...
Adam's user avatar
  • 151
5 votes
1 answer
10k views

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:...
user54's user avatar
  • 583
4 votes
3 answers
9k views

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=${...
David West's user avatar
  • 1,503
3 votes
1 answer
1k views

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 ...
Auto-learner's user avatar
3 votes
0 answers
2k views

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 ...
Argyle's user avatar
  • 1,026
2 votes
1 answer
13k views

Why does Jenkins Pipeline script returnStatus value not match status examined in shell?

This is my little newbie Groovy script, trying to cobble together a very beginner understanding of Jenkins Pipelines: node { stage("hello") { def var = "val" echo "${var}&...
StoneThrow's user avatar
2 votes
1 answer
4k views

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 ...
rodee's user avatar
  • 177
2 votes
1 answer
10k views

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 ...
kotezbuzzi's user avatar
2 votes
1 answer
10k views

Jenkinsfile script to waitUntil a folder is created

With this Jenkinsfile code, I am trying to test A/B folder creation, and also testing if waitUntil works till the folder is created, I expect it to wait for 0 secs as the folder is created before ...
rodee's user avatar
  • 177
2 votes
1 answer
5k views

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 ...
Janith's user avatar
  • 173
2 votes
1 answer
2k views

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....
Alter_so's user avatar
2 votes
3 answers
12k views

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 = "...
omkar sirra's user avatar
1 vote
1 answer
1k views

Is it possible to combine failure stage from groovy with try catch from pipeline?

I have a pipeline with some stages and logic. The only possible debugger is adding try-catch to each stage: stage ("distribution"){ steps{ script{ try{ ...
arielma's user avatar
  • 339
1 vote
2 answers
5k views

Jenkins pipeline lock resources

I need to run commands on my pipeline during a certain stage, on devices which connected to my Jenkins as slaves. But I want them to run only when another one finished. On the other hand, I want them ...
amichib's user avatar
  • 115
1 vote
1 answer
1k views

Is it possible to send email notification for Input (GO/NOGO) from a pipeline

There is User input functionality in the declarative pipeline which prompt on the Jenkins console but it's a headache to login every time on console and select the appropriate action. So I want to ...
Nullpointer's user avatar
1 vote
1 answer
389 views

In Jenkins, how can I disable "Discard old builds" option via pipeline?

I have several jobs where I want to disable the option shown below in the jobs' configuration page. How can I do it via pipeline?
Chris F's user avatar
  • 475
1 vote
2 answers
610 views

Reuse block string without processing it on the fly

I have a block of code that work fine at the moment. But reuse that code is a little ugly. pipeline { agent any stages { stage('Stage 1') { steps { script { ...
navebinario's user avatar
1 vote
1 answer
870 views

jenkins parameter behaves differently from internally defined variable

I set up my jenkins job to take in the parameter payload and set its value to test\ntest. My jenkins script is the following: def hardset = "test\ntest" echo "param:" def cleanParam = jenkinsParam....
Alex's user avatar
  • 4,582
1 vote
1 answer
8k views

how to create dynamic stages in jenkins pipeline

I want to use a python script as input to create stages in jenkins pipeline test.py {'job-name': 'Test1', 'action': 'a', 'targetname': 'x'} {'job-name': 'Test2', 'action': 'b', 'targetname': 'y'} {'...
Pavithra's user avatar
1 vote
1 answer
4k views

Jenkins - Active Choice DynamicReferenceParameter not returning list

I have been trying unsuccessfully to get DynamicReferenceParameter of the Active Choice plugin to show previously selected values as list, however it either shows them on one line or it treats each ...
Filip Nikolov's user avatar
1 vote
1 answer
2k views

How do i print the list of jobs per plugin in Jenkins

I'm trying to list the jenkins jobs per plugin is being utilized. I see there's a plugin in jenkins, https://github.com/jenkinsci/plugin-usage-plugin, which displays the plugins usage in the Jenkins ...
Sachin's user avatar
  • 11
1 vote
1 answer
53 views

How to handle services when the developers provide incorrectly in k8s

I provided the script to provision a new feature environment inside k8s it will create all the configs required, namespaces, resources and whatever... in my script, I described this param: parameters {...
Mkash's user avatar
  • 23
1 vote
1 answer
1k views

How to add job dependency to gerrit trigger in Jenkins pipeline?

We do have this configuration in our GUI based Jenkins project, trying to convert it to Jenkins pipeline, couldn't find how to add precurse-build as dependent build as shown in red below. I added ...
rodee's user avatar
  • 177
1 vote
1 answer
3k views

How to pass groovy output to pipeline variable

I have the below code in the jenkisn pipeline: stage ("amd_distribution_input_transformation"){ steps{ script{ amd_distribution_input_transformation url: ...
arielma's user avatar
  • 339
1 vote
1 answer
458 views

How to assign saltstack pillar values from Jenkins comma separated input parameters?

I have a Jenkins job with string parameter as target "server1,server2". Jenkins pipeline script is expected to execute the job on server1 and server2 respectively. There is a common salt sls file that ...
Narasimha's user avatar
1 vote
1 answer
889 views

Compatibility of http-builder-ng Groovy module with Jenkins 2

Did somebody had a chance to use http-builder-ng Groovy module in Jenkins pipeline? When I use this module with any kind of request/URL it always returns me null object when the same source code ...
user54's user avatar
  • 583
1 vote
3 answers
467 views

How can I use a pipeline Jenkins shared library to implement encapsulation, inheritance, and polymorphism?

I'm trying to implement the Builder design pattern in a Jenkins pipeline shared library. Say I have the following file structure and pseudo-code (to only illustrate the concept I'm after) src/com/...
Chris F's user avatar
  • 475
1 vote
2 answers
5k views

Jenkins Credentials Manager + Active Choices

I want to access Jenkins Credentials to authenticate with Git before the pipeline script - to fill Active Choices parameter. In the pipeline I simply do it with withCredentials. But during pre-...
pfoof's user avatar
  • 13
1 vote
1 answer
12k views

Set environment variables then run script in Jenkins Scripted Pipeline

I am new to Jenkins, Groovy and pipelines. I have created a simple pipeline stage like so: //working build but not setting env variables node('build-01') { stage('Building') { echo "[*] ...
Perplexabot's user avatar
0 votes
1 answer
2k views

java.lang.UnsupportedOperationException: no known implementation of class jenkins.tasks.SimpleBuildWrapper is named BuildUser in jenkins

I preparing script in Jenkins as below where I getting error while build job. This job is send email to user for input for next step. [Pipeline] End of Pipeline java.lang....
Nullpointer's user avatar
0 votes
1 answer
966 views

Jenkinsfile credential as paramter unable to use it

I am trying to use the credentials parameter for a git clone. But i am getting the error that the variables are not found Param definition credentials (credentialType: 'Username with password', ...
Vini's user avatar
  • 121
0 votes
1 answer
6k views

How to save groovy output to pipeline variable

I have the below code in the jenkisn pipeline: stage ("amd_distribution_input_transformation"){ steps{ script{ amd_distribution_input_transformation url: ...
arielma's user avatar
  • 339
0 votes
1 answer
155 views

Does Jenkins job create Jenkinsfile? On execution

On creation of a new job(as free style project), and running it, I see that Jenkinsfile is generated in job's workspace, after running the job. But I see that all the pipeline code is commented. ...
overexchange's user avatar
0 votes
2 answers
985 views

How to modify a Jenkins pipeline job's property programmatically?

We set up a Jenkins job in multiple folders that has the following "Choice Parameter" property. How can I modify the property programmatically to add more choices? For example, I want to ...
Chris F's user avatar
  • 475
0 votes
1 answer
7k views

Running this groovy jenkins script output this error "WorkflowScript: 17: expecting '}', found ':' @ line 17, column 11"

#!groovy env.BEARER_TOKEN = "uuuuuuuuuu" node { publishModule() } def publishModule() { stage('Deploy Modules') { } } def buildPayload() { def payload = { "data&...
green_car's user avatar
0 votes
1 answer
1k views

In jenkins how to restrict users to select first default element with other options in extended choice parameter

I have a jenkins job with multi select extended choice parameter. There are list of elements in a parameter. So, my requirement is I want to allow users to select multiple parameters excluding first ...
Jenkins-Learner's user avatar
0 votes
1 answer
608 views

Execute python file existing inside image with Jenkins

I have an Image A, which has a python file "main.py". I want to know how I can use Jenkins to run that file from a different pipeline. I want to use Jenkins to go inside that image and then ...
Taziamoma Abraham's user avatar