Jenkins Pipeline, getting runWrapper references even on failed runs

Viewed 697

I'm trying to run multiple builds in parallel in jenkins pipeline and get the result of those builds. My code looks something like

runWrappers = []

script {
    def builds = [:]
    builds['a'] = { runWrappers += build job: 'jobA', parameters: /* params here*/ }
    builds['b'] = { runWrappers += build job: 'jobB', parameters: /* params here*/ }
    builds['c'] = { runWrappers += build job: 'jobC', parameters: /* params here*/ }
    builds['d'] = { runWrappers += build job: 'jobD', parameters: /* params here*/ }

    parallel builds
    // All the builds are ran in parallel and do not exit early if one fails
    // Multiple of the builds could fail on this step
}

If there are no failures, the pipeline continues onto other stages. If there is a failure, an exception will be thrown and the following post-build code will run immediately

post {
    always {
        script {
            def summary = ''
            for (int i; i < runWrappers.size(); i++) {
                def result = runWrappers[i].getResult()
                def link = runWrappers[i].getAbsoluteUrl()
                summary += "Build at: " + link + " had result of: " + result
            }
            /* Code to send summary to external location */
        }
    }
}

This works for the most part. The problem is that this code will only print out the result for the builds that result in a SUCCESS because the builds that fail throw an exception before returning a reference to a runWrapper.

Is there a way to get a reference to a runWrapper or similar that can give me information (mainly the url and result) on a failed build? Or is there a way for me to get such a reference before I start the build and cause an exception?

1 Answers

Try to use propagate: false:

build job: 'jobA', propagate: false, parameters: /* params here*/

But in this case your parallel won't fail anymore.

Related