Mike Cooper
Mike Cooper

Reputation: 1105

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?

Upvotes: 7

Views: 10190

Answers (4)

YtachY
YtachY

Reputation: 1

Check pipeline log in Artifact > pipeline.log in blue ocean UI.

Jenkins pipeline in BlueOcean UI

Jenkins pipeline in BlueOcean UI

In my case: I use Scripted Pipeline and there is

...
No such DSL method 'post' found among steps
...

error log


My Jenkinsfile looks like this when it failed. I should remove post block due to the error log above.

#!/usr/bin/env groovy

node("android") {
    stage("ENV") {
        sh "printenv"
        sh "java -version"
        if (env.ANDROID_HOME == null || env.ANDROID_HOME == "") error "ANDROID_HOME not defined"
    }
    stage ("SCM") {
        checkout([
            $class: 'GitSCM',
            ...
        ])
    }
    stage("clean") {
        sh "./gradlew clean --no-daemon"
    }
    stage("build") {
        sh "./gradlew... 
    }
    stage("archive") {
        sh "echo DONE"
    }
    stage('commit ') {
        cleanWs()
        def scmVars = checkout scmGit(branch ...
    }
    post{
        always{
            echo "====++++always++++===="
            sh "ls -lah"
        }
        success{
            echo "====++++only when successful++++===="
            cleanWs()
            sh "ls -lah"
        }
        failure{
            echo "====++++only when failed++++===="
        }
    }
}

Upvotes: 0

pradeep kumar
pradeep kumar

Reputation: 9

I was facing similar issue . The reason was I used publishhtml , and the repot folder was missing , which threw error in console log , but stage passed (GREEN) and job showed RED (failed).

Upvotes: 1

Carolina Herrera
Carolina Herrera

Reputation: 84

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

environment {
            EMAIL_TO = '[email protected]'
        }
    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'
            }

        }

Upvotes: 1

Carolina Herrera
Carolina Herrera

Reputation: 84

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.

Upvotes: 0

Related Questions