Jenkins build Failed but all stages Succeeded

Viewed 5366

I have a Jenkins pipeline that all stages complete and report as Success but the overall build is marked as Failed. This occurs every time a build is run. Builds are run from start to finish without any "continue from last stage". The jenkins version and plugins are all updated to current.

If I look at each stage it says "Success" in the hover-over (see screenshot).

What am I missing here?

My Jenkinsfile enter image description here enter image description here

EDIT 1: Adding blue ocean screenshot: enter image description here

The end of the pipeline log file:

[Pipeline] }
[Pipeline] // withEnv
Post stage
[Pipeline] junit
Recording test results
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] mail
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: FAILURE

EDIT 2: Added post section

Here is the end of the pipeline statement:

post {
    failure {
        mail to:    "$MAIL_NOTIFY",
        subject:    "Failed Pipeline: ${currentBuild.fullDisplayName}",
        body:       "Something is wrong with ${env.BUILD_URL}"
    }
}

EDIT 3: Removed post failure

If I remove the "post { failure { mail ... } }" section then the build completes successfully. So the question is now... How do I fix this section to work properly?

3 Answers

As the send email step is failing, can you try using:

environment {
            EMAIL_TO = 'someone@host.com'
        }
    post {
            failure {
                emailext body: 'Check console output at $BUILD_URL to view the results. \n\n ${CHANGES} \n\n -------------------------------------------------- \n${BUILD_LOG, maxLines=100, escapeHtml=false}', 
                        to: EMAIL_TO, 
                        subject: 'Build failed in Jenkins: $PROJECT_NAME - #$BUILD_NUMBER'
            }

        }

You need to check the Console log of that job, though all the stages Succeded, there must be a step that is failing at last part.

If you want to send an e-mail to the right developer, you can try something like this :

pipeline {
    agent any 
    stages {
        stage('A') {
            steps {
                ...
            }
        }
        stage('Test') {
            steps {
                ...
            }
        }
    }
    post { 
        always {
                emailext  body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
                recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
                subject: "[Jenkins] Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
        }
    }
}
Related