Some days ago i wrote a post about how to get the overall status in the upstream job from the downstream jobs in Hudson or Jenkins (https://fatalfailure.wordpress.com/2011/06/14/jenkins-hudson-getting-the-overall-status-in-the-upstream-job-from-the-downstream-jobs/).
A user (v22 ) test my code and had some problems, and actually, there is a problem.
As i said in the comment reply, there is a problem in the execution order of the post build actions, this is not deterministic and depends on how the job configuration is stored in a XML file located in the master node.
The relationship between the upstream jobs and the downstream jobs is ready when the fingerprints are recorded. This action is done on a post build action, like the Groovy execution. If the Groovy execution is performed before the fingerprint recording, there is not upstrem job set yet, therefore the Groovy code fails.
I proposed in that reply a workaround to change the order execution of the post build actions, but this is not working as i expected, so there is not a way to force the Groovy execution after the fingerprint recording.
There is an open ticket in the Jenkins and Hudson issue tracker to add a way to specify the post build actions executions: https://issues.jenkins-ci.org/browse/JENKINS-7408
But everything has a solution, and a solution that always works 😉
There is a plugin called “Join Plugin” (https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin) that let you execute jobs after all the downstream jobs finish.
The only thing you need to do is configure the upstream job with the Join plugin setting a new job (“Join job”) to be executed after all the downstreams are finished. In that “Join job” you need to add the Groovy code with the Groovy postbuild plugin.
The code here would be more sophisticated, but not very complex.
Take a look to the code i wrote in my post and edit it, i’m not going to write the new code here, i’ll let you investigate a bit. But here are some clues:
- Instead of use getUpstreamBuilds(), you will need getTransitiveUpstreamBuilds()
- Once you have the upstream job, use getDownstreamProjects() to get the downstream jobs
- Loop over the downstream jobs checking their states and update the upstream job accordingly
You can remove the Groovy code in the downstream jobs.