I need some help with pipeline. I probably miss some trivial info here.
So I have the following example pipeline:
pipeline {
agent any
stages {
stage('Build') {
steps {
... some build steps (irrelevant) ...
}
}
stage('Test'){
steps {
sh 'find . -type f -name "*.php" -exec php56 -l {} \\;'
}
}
}
post {
success {
echo 'posting success to GitLab'
updateGitlabCommitStatus(name: 'jenkins-build', state: 'success')
}
failure {
echo 'posting failure to GitLab'
updateGitlabCommitStatus(name: 'jenkins-build', state: 'failed')
}
}
}
As a test, I intentionally created broken PHP code, and when I run the line find . -type f -name "*.php" -exec php56 -l {} \\;
manually in my codebase, I see that it detects the error.
Also, in the Jenkins job's console output I see the same: it detects the error.
However, my success block is then triggered. Am I not using the success / failure block correctly?
When I add a syntax error to the find statement itself (for example discard the \\;
part) an error will trigger and it will result in failure as expected.
Edit (about duplicate question)
This question has been marked as a duplicate of another question, but since the information I actually needed was about the fact when a step or sh-step fails. Because this post and answer contains relevant info for others looking for, I'll keep it like this.