Programmatically access children builds in Jenkins build flow
It took me a while to play with the Build Flow and Jenkins API, and finally I got this:
import hudson.model.*import groovy.json.*// Assign a variable to the flow rundef flow = parallel( {build("child-dummy", branch_name: "child1")}, {build("child-dummy", branch_name: "child2")})println 'Main flow ' + flow.getClass().toString() + ', size: ' + flow.size()flow.each { it -> // type = com.cloudbees.plugins.flow.FlowState def jobInvocation = it.getLastBuild() // type = com.cloudbees.plugins.flow.JobInvocation println 'Build number #' + jobInvocation.getNumber() println 'Build URL ' + jobInvocation.getBuildUrl()}
To obtain details of the run, such as artifacts etc. from the child jobs, use jobInvocation.getBuild()
method that returns a Run
instance.
Getting the Junit results should be easy by parsing the JSON result file as specified in How to get the number of tests run in Jenkins with JUnit XML format in the post job script?.