42

Figured it out. Outside of any stages (otherwise this will just end the particular stage as a success) do the following; if( $VALUE1 == $VALUE2 ) { currentBuild.result = 'SUCCESS' return } return will stop the stage or node you're running on which is why running it outside of a stage is important, while setting the currentBuild.result prevents it ...


13

Jenkins can filter branches in a multibranch pipeline by name using a wildcard or regular expression.


12

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 JENKINS_SERVER_COOKIE. None of them work for pipeline project. Refer to https://issues.jenkins-ci.org/browse/JENKINS-28182 for more details.


9

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 does not visualise this properly. Possible solutions discussed here


8

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 (your condition) { autoCancelled = true error('Aborting the build.') } } } catch (e) { if (autoCancelled) { currentBuild.result = '...


8

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' }


8

You may try something like this: node('my_kubernetes_pod') { passedBuilds = [] lastSuccessfulBuild(passedBuilds, currentBuild); def changeLog = getChangeLog(passedBuilds) echo "changeLog ${changeLog}" } def lastSuccessfulBuild(passedBuilds, build) { if ((build != null) && (build.result != 'SUCCESS')) { passedBuilds....


7

You can use the checkout scm step whenever you need the source: pipeline { agent none options { skipDefaultCheckout() } stages { stage('Build') { agent { node { label 'builder' } } steps { checkout scm echo 'build-the-app' stash(name: 'app', includes: 'outputs') } } stage('Test') { agent { ...


7

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 ( ['THIS-SHOULD-HAVE-BEEN-A-UNIQUE-ID-INSTEAD-OF-A-NAME']) {


6

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[currentExecutable[url]],oneOffExecutors[currentExecutable[url]]]&xpath=//url&wrapper=builds I greped it for a count and used that for my calculations.


6

In Groovy you have to use double quotes to get string interpolation: if ( "$output" != null ) { slackSend (channel: "@${name}", color: '#36A64F', message: "Job succeeded") } else { slackSend (channel: "@${name}", color: '#36A64F', message: "Job failed") } You can also probably do something like this to avoid it entirely and have ...


6

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 this a step further and whenever a green light turns up, automatically deploys that. Note that "tested" above can mean several steps: smoke tests (does it crash ...


5

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/parallelFromList.groovy Here is a simpler example to run things in parallel if you only have a fixed number of things you want to do in parallel: parallel ( ...


4

I had a similar situation in which I wanted to nest other parallel jobs threads inside another parallel one. This code worked for me: def performDeploymentStages(String node, String app) { stage("build") { echo "Building the app [${app}] on node [${node}]" } stage("deploy") { echo "Deploying the app ${app}] on node [${node}]" ...


4

To synthesize Alex and Steve Johnson's answers, you could put this at the top of your downstream job: lastBuild = currentBuild.getPreviousBuild() delay = 2 if Date(lastBuild.timestamp) >= new Date().minusHours(delay) { currentBuild.result = 'SUCCESS' echo "Less than ${delay} hours since the last build. Job will not run." return }


4

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 solutions would parse the output of git-add and only run git-commit when there is something to commit.


4

Your question is sitting unanswered here because you're way "out in the weeds" - running pretty idiosyncratic batch scripts that seem to leverage cygwin on Windows, in short, you're in the "wtf" category here. That's ok! In this work, all of us are in this place for a lot of our day. I suggest you consider switching these up for powershell tasks, you can ...


4

"This is great, but I want to run a command/script when a branch is removed, how can I have jenkins run a command when a branch is removed?" You will need to use a webhook for this, I use the following settings in Github: Bitbucket only supports the following webhooks: "Is there a way to have Jenkins trigger a job before it removes the branch?" ...


4

I see two approaches : Save current branch name on a variable and check it in a if statement CURRENT_BRANCH = '...' // some value or parameter stage('only on master') { if (CURRENT_BRANCH == 'master') { input { ... } } // be sure to check if input was set or define a default value or Run a shell script to know if current folder is a git ...


4

def suiteRunId = UUID.randomUUID().toString() worked at the top of the Jenkinsfile. Thanks all for your answers.


4

You need to define variables before the pipeline block starts. Then it should be work. def foo = "foo" pipeline { agent none stages { stage("first") { sh "echo ${foo}" } } }


3

You can have conditionals in your declarative pipeline by using the when-block inside a stage. There is a plugin called "environment injector" which lets you set variables outside of the pipeline-script which is nice. Also if you put the step below the other steps, it won't execute if they fail. when { environment name: 'pushArtifact', value: 'true' }...


3

buildEnv.inside("-u 0") {} resolved my problem. But then the workspace will contains directory and files owned by root which can not be deleted by the user Jenkins at the next run when cleaning the workpace , so I have added sh "sudo chown jenkins: -R \$PWD/" at the beginning of the pipeline.


3

I just had a similar issue today, although with another image. docker { image 'node:8' args '--tmpfs /.config' } Reference: https://docs.docker.com/storage/tmpfs/ This way you shouldn't be worried about any security leaks or files which are present after the container is destroyed inside the jenkins.


3

Working off what @chupasaurus said, here's what I came up with: node('master') { dir("../builds/${BUILD_NUMBER}/") { sh "cp -r cucumber-html-reports $WORKSPACE" } archive "cucumber-html-reports/*" } Obviously all this does is archive the report for that build, but you can easily extend this to copy it somewhere else where it can be ...


3

This is a known bug. See JENKINS-42878 and JENKINS-41996. This bug has been resolved upstream, which means you should be able to fix the bug by upgrading the plugin to the latest version.


3

It sounds like maybe you need to configure a webhook for git if you are using the git plugin, but I think that may just build the master branch. I haven't used git much, so you might be able to use the web hook to have it build the pull request - I don't know. Instead, you might want to check out the pull request builder plugin and see if that does what you ...


3

To me, but correct me if I am wrong, the Jenkins servers should not be rebooted, but they should create VMs and reboot them. When I read the question I get the impression the slaves are rebooted, i.e. I can't just use the executor on the slave node because we reboot the server and that would kill the job. To me it seems that the jenkins slave should create a ...


3

Yes, this is pretty easy with Jenkinsfiles with no need for any third-party plugins or anything along those lines: use the built-in Pipeline build step. I use this to trigger builds of projects in a dependency chain, so that after one project builds successfully, other projects that depend on it will pull in the updated dependency and build against it. ...


3

I am assuming you are using Jenkinsfile. You can do for example: pipeline { agent any stages { stage('Build') { steps { echo 'Building..' } } stage('Test') { steps { echo 'Testing..' } } stage('Deploy') { when { ...


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