In a declarative pipeline, using a multibranch job and a Jenkinsfile, can the job be aborted with a success
exit code rather than a failure
exit code?
In the below stage, I basically check if the commit that started the job contains "ci skip", and if it does I want to abort the job.
Using error
aborts the job but also marks it as such (red row). I'd like this job to be marked with a green row.
stage ("Checkout SCM") {
steps {
script {
checkout scm
result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
if (result == 0) {
error ("'ci skip' spotted in git commit. Aborting.")
}
}
}
}
Edit:
Instead of the above, I am now trying to simply skip all stages in case the git commit contains "ci skip". My understanding is that if the result in expression
is false
, it should skip the stage...
pipeline {
environment {
shouldBuild = "true"
}
...
...
stage ("Checkout SCM") {
steps {
script {
checkout scm
result = sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
if (result == 0) {
echo ("'ci skip' spotted in git commit. Aborting.")
shouldBuild = "false"
}
}
}
}
stage ("Unit tests") {
when {
expression {
return shouldBuild
}
}
steps {
...
}
}
...
...
}