Jenkins Pipeline sh display name/label

Update Feb 2019: According to gertvdijk’s answer below, it is now possible to assign an optional label to the sh step, starting from v2.28, and for those who can’t upgrade yet, there’s also a workaround. Please check his answer for details and comments! Previous version (hover to see it): As far as I know, that’s … Read more

Jenkins: Pipeline sh bad substitution error

This turned out to be a syntax issue. Wrapping the command in ‘‘s caused ${env.BUILD_NUMBER to be passed instead of its value. I wrapped the whole command in “s and escaped the nested. Works fine now. sh “curl -v –user user:password –data-binary ${buildDir}package${env.BUILD_NUMBER}.tar -X PUT \”http://artifactory.mydomain.com/artifactory/release-packages/package${env.BUILD_NUMBER}.tar\””

How do I implement a retry option for failed stages in Jenkins pipelines?

You should be able to combine retry + input to do that Something like that stage(‘deploy-test’) { try { build ‘yourJob’ } catch(error) { echo “First build failed, let’s retry if accepted” retry(2) { input “Retry the job ?” build ‘yourJob’ } } } you could also use timeout for the input if you want … Read more

How to use multiple credentials in withCredentials in Jenkins Pipeline

Sure, you can use one withCredentials block to assign multiple credentials to different variables. withCredentials([ usernamePassword(credentialsId: credsId1, usernameVariable: ‘USER1’, passwordVariable: ‘PASS1’), usernamePassword(credentialsId: credsId2, usernameVariable: ‘USER2’, passwordVariable: ‘PASS2’) ]){ //… }

Show a Jenkins pipeline stage as failed without failing the whole job

This is now possible, even with declarative pipelines: pipeline { agent any stages { stage(‘1’) { steps { sh ‘exit 0’ } } stage(‘2’) { steps { catchError(buildResult: ‘SUCCESS’, stageResult: ‘FAILURE’) { sh “exit 1” } } } stage(‘3’) { steps { sh ‘exit 0’ } } } } In the example above, all stages … Read more

Jenkins: Ignore failure in pipeline build step

To ignore a failed step in declarative pipeline you basically have two options: Use script step and try-catch block (similar to previous proposition by R_K but in declarative style) stage(‘someStage’) { steps { script { try { build job: ‘system-check-flow’ } catch (err) { echo err.getMessage() } } echo currentBuild.result } } Use catchError stage(‘someStage’) … Read more

How to invoke a jenkins pipeline A in another jenkins pipeline B

Following solution works for me: pipeline { agent { node { label ‘master’ customWorkspace “${env.JobPath}” } } stages { stage(‘Start’) { steps { sh ‘ls’ } } stage (‘Invoke_pipeline’) { steps { build job: ‘pipeline1’, parameters: [ string(name: ‘param1’, value: “value1”) ] } } stage(‘End’) { steps { sh ‘ls’ } } } } Adding … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)