In a declarative pipeline, using a multivariate job and a Jenkins file, can work be interrupted with an exit code success
rather than an exit code failure
?
In the next step, I basically check if the commit that started the job contains "ci skip", and if so, I want to interrupt the work.
Use error
interrupts the task, but also marks it as such (red line). I would like this work to be marked with a green line.
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'm now trying to simply skip all the steps if git commit contains "ci skip". I understand that if the result is expression
equal 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 {
...
}
}
...
...
}