5

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`)
        }
    }
}
Shane Gannon
  • 6,770
  • 7
  • 41
  • 64
  • How do you define "build failure"? Is it a stage that failed? Is it a failure to e.g. bring up a container? This depends on your project's logic, that's why every project has it different. – MaratC Mar 26 '20 at 10:38
  • I get where you're coming from. Namely that the reason for a failure can be complex. But whatever caused the overall build status to move to FAILURE, ABORT, etc would be a decent starting point. – Shane Gannon Mar 27 '20 at 10:19
  • In the answers you've linked, there's a description of a solution. – MaratC Mar 27 '20 at 12:02

1 Answers1

0

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.

Shane Gannon
  • 6,770
  • 7
  • 41
  • 64