Jenkins Pipeline Failure Reason

Viewed 1062

I've come across older questions on this topic. Namely

But, by now, I'd expect the Jenkins Pipeline to have this functionality baked, rather than hacked, in.

When running a post script in a Jenkins Pipeline is there any way to find the build failure? e.g. Via an environmental variable, currentBuild, etc.

pipeline {
    agent none
    stages {
        stage("Validate") {
            parallel {
                stage("Ubuntu") {
                    agent {
                        label "UBUNTU"
                    }
                    steps {
                        sh "cause failure"
                    }
                }
            }
        }
    }
    post { 
        failure { 
            sendFailureMessage(`failure reason here`)
        }
        aborted { 
            sendFailureMessage(`failure reason here`)
        }
        unstable { 
            sendFailureMessage(`failure reason here`)
        }
    }
}
1 Answers

For prosperity I ended up creating a script to read the test failures from the test-results.xml file. This is not ideal - by which I mean convenient. But I could find no built in approach that'd work. Which is a pity as Jenkins already parses that file and should have the results available somewhere.

Related