Skip to main content
96 votes
Accepted

Cleanest way to prematurely exit a Jenkins Pipeline job as a success?

Please note: The following works for scripted pipelines only. For a solution for declarative pipelines see @kgriffs' answer. --- Figured it out. Outside of any stages (otherwise this will just end the ...
Alex's user avatar
  • 4,552
29 votes
Accepted

How to disable some branches in Multibranch Jenkins Builds?

Jenkins can filter branches in a multibranch pipeline by name using a wildcard or regular expression.
casey vega's user avatar
26 votes

How to define variable in Jenkins declarative pipeline?

The variable must be defined in a script section. pipeline { agent none stages { stage("first") { steps { script { foo = &...
plmaheu's user avatar
  • 381
25 votes

Cleanest way to prematurely exit a Jenkins Pipeline job as a success?

The Executor.interrupt(Result) method is the cleanest, most direct way I could find to stop a build prematurely and mark it as a success. script { currentBuild.getRawBuild().getExecutor()....
Ben Amos's user avatar
  • 371
22 votes
Accepted

Running a background process in Pipeline job

Any one facing the same problem and using pipeline project, set JENKINS_NODE_COOKIE instead of BUILD_ID. Dont waste your time setting HUDSON_COOKIE, HUDSON_SERVER_COOKIE, JENKINS_COOKIE or ...
Dharanidhar's user avatar
22 votes

Cleanest way to prematurely exit a Jenkins Pipeline job as a success?

You can also use error to exit the current stage, then you don't have to consider the current stage hierarchy and similar stuff: def autoCancelled = false try { stage('checkout') { ... if (...
CSchulz's user avatar
  • 321
21 votes
Accepted

What is the difference between Jenkin's `Replay` and `Rebuild` options?

Rebuild, using the Rebuilder plugin allows a completed job to be re-executed while allowing you to change the parameters, assuming your job is parameterized. Replay does something similar, except it ...
Argyle's user avatar
  • 1,026
15 votes

Triggering specific pipeline builds for monorepos in Jenkins

You can use the "when" block combined with the built in "changeset" condition to conditionally run only certain stages of your monorepo's pipeline. From the when.changeset documentation: changeset- ...
mancini0's user avatar
  • 251
14 votes

Jenkins: Permission issue using Docker as build environment

I had the same issue with node. The thing is files in the container are owned by "root:root". Try adding docker args -u root:root: docker { image 'node:8' args '-u root:root' }
blurrcat's user avatar
  • 241
13 votes

Cleanest way to prematurely exit a Jenkins Pipeline job as a success?

If it is acceptable to set the build status to ABORTED instead of SUCCESS, the following snippet may be used within a pipeline stage to short-circuit the build: steps { script { ...
kgriffs's user avatar
  • 231
12 votes
Accepted

Get all change logs of since last successful build in Jenkins Pipeline

You may try something like this: node('my_kubernetes_pod') { passedBuilds = [] lastSuccessfulBuild(passedBuilds, currentBuild); def changeLog = getChangeLog(passedBuilds) echo "...
user54's user avatar
  • 583
11 votes
Accepted

How to build a complex parallel Jenkins pipeline?

Based on the comments to my question, and some basic testing the following seems to work: Use nested parallel statements. (Thanks @lawnmowerlatte) Although today (May 15th 2017) Jenkins Blue ocean ...
Bert Goethals's user avatar
11 votes

Jenkins shows the job as failed if there is nothing to commit to gitlab

In my automatic jenkins job, launched daily, if there are no changes the git commit command returns 1. That will mark the build as failed. To solve this problem I use these two commands in my shell ...
Francesco Fornari's user avatar
10 votes
Accepted

sshagent and jenkinsfile

Found the problem: I was using the human readable key name from the GUI. Need to use the key's UUId ID instead (this is specified next to the name in credentials screen) steps { sshagent ...
eshalev's user avatar
  • 281
9 votes

How to retrigger a Jenkins build after failure using declarative syntax?

The other answer is incorrect. There is indeed a builtin to retry arbitrary sections of your job called retry. If you want to retry the whole job three times, you can wrap your entire job in a retry ...
jayhendren's user avatar
  • 2,952
9 votes
Accepted

Passing variables between scripts in a Jenkins pipeline

For Declarative Pipeline: This question already has a highly-upvoted answer on StackOverflow: If you want to use a file (since a script is the thing generating the value you need): pipeline { ...
jayhendren's user avatar
  • 2,952
8 votes
Accepted

Jenkins API call (or Groovy builtin) that returns list of all currently running builds of jobs

Turns out you can hit the following URL to get an XML output of all currently running builds, including their build numbers. http://jenkinsURL/computer/api/xml?tree=computer[executors[...
Alex's user avatar
  • 4,552
8 votes

How to check out GitHub repo after specifying skipDefaultCheckout in Jenkins declarative pipeline?

You can use the checkout scm step whenever you need the source: pipeline { agent none options { skipDefaultCheckout() } stages { stage('Build') { agent { node { label 'builder' } } ...
burnettk's user avatar
  • 466
8 votes
Accepted

One Jenkinsfile or multiple?

It really comes down to personal preference. One additional tool you might not be aware of are shared libraries for Pipeline. These allow you to quickly write custom Pipeline steps or factor out ...
jayhendren's user avatar
  • 2,952
7 votes
Accepted

How not to break Jenkins Pipeline when adding new parameters (declarative pipeline)

Here is a solution which seems almost like a workaround that I have found which works for declarative pipelines. First, we need to add some code at the start of our file before we enter into the ...
Inbar Rose's user avatar
7 votes

How to define variable in Jenkins declarative pipeline?

You can also use environment block to inject an environment variable. (Side note: sh is not needed for echo) pipeline { agent none environment { FOO = "bar" } stages { ...
modle13's user avatar
  • 181
7 votes
Accepted

Jenkins Declarative pipeline: Execute stage conditional on execution of previous stage

A pretty simple solution is to declare a global variable on top of your pipeline, and check it's value in your last conditional stage: def flag = false; pipeline { stages { stage('1 - ...
Hedi Nasr's user avatar
  • 746
6 votes
Accepted

Jenkins shows the job as failed if there is nothing to commit to gitlab

In order to get a success, you need to avoid non-zero exit codes. A simple solution would be to change the last line of your script to git commit -a -m 'Changes pushed by Jenkins' || true, but better ...
Jesusaur's user avatar
  • 196
6 votes
Accepted

Jenkins Pipeline job; proper quoting for slackSend step

In Groovy you have to use double quotes to get string interpolation: if ( "$output" != null ) { slackSend (channel: "@${name}", color: '#36A64F', message: "Job succeeded") } else { ...
Michael Pereira's user avatar
6 votes

Jenkins Artifactory plugin not downloading in multi-thread

You could try to run the artifactory file upload in parallel if you are using the Jenkinsfile syntax: https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/parallel-from-list/...
Michael Pereira's user avatar
6 votes
Accepted

How to perform continuous Integration using Jenkins?

Continuous integration means roughly what you said. Whenever something is committed, it is automatically built and tested, with a red/green light showing up at the end. Continuous deployment takes ...
AnoE's user avatar
  • 4,906
6 votes
Accepted

Jenkins Job vs Jenkins Pipeline

Jenkins Job and Jenkins Pipeline are basically the same. In a pipeline you define the steps of your job as groovy code (actually it is CPS https://github.com/jenkinsci/workflow-cps-plugin, but that ...
Max N.'s user avatar
  • 413
6 votes
Accepted

Jenkins UUIDs ... oh the humanity

def suiteRunId = UUID.randomUUID().toString() worked at the top of the Jenkinsfile. Thanks all for your answers.
David West's user avatar
  • 1,493
6 votes
Accepted

Jenkins Pipeline "Build when a change is pushed to GitLab"

Looks like you are using the Gitlab plugin for jenkins? if so this link should be of help https://github.com/jenkinsci/gitlab-plugin#declarative-pipeline-jobs
Nune Isabekyan's user avatar
6 votes

How to trim spaces for parameter value in jenkins pipeline?

Use the Groovy trim() method. For instance, def myTrimmedParam = params.myParam.trim().
jayhendren's user avatar
  • 2,952

Only top scored, non community-wiki answers of a minimum length are eligible