0

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.

vrijdenker
  • 1,371
  • 1
  • 12
  • 25
  • Possible duplicate of [How to exit from find -exec if it fails on one of the files](https://stackoverflow.com/questions/14871147/how-to-exit-from-find-exec-if-it-fails-on-one-of-the-files) – StephenKing Jul 20 '17 at 13:58

1 Answers1

0

Jenkins will treat the executing of the sh step as failed, if the command exits with a non-zero exit status. So your question boils down to How to exit from find -exec if it fails on one of the files.

StephenKing
  • 36,187
  • 11
  • 83
  • 112