Jenkins Pipeline getting RunWrapper links even on failed runs

I am 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 goes to other stages. If it fails, an exception will be thrown and the next 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 the output for the assembly, which results in SUCCESS because assemblies that do not throw an exception before returning a reference to runWrapper.

Is there a way to get a link to runWrapper or similar that can give me information (mainly url and result) about the failed build? Or do I have a way to get such a reference before I start the build and get out of the exception?

+3


source to share


1 answer


Try using propagate: false

:

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

      



But in that case, yours parallel

won't fail anymore.

+2


source







All Articles