jenkins

Jenkins build Failed but all stages Succeeded


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?


Solution

  • 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'
                }
    
            }