1
votes

I need to spawn a variable number of jobs from one upstream job. AFAIK, there is no plugin that can do this. The closest one is MultiJob plugin (https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin). So I thought to create a build step that would use one of the Jenkins APIs (REST, groovy or jenkins-cli) to trigger those builds. However, if I do that, those builds become "detached" (meaning they do not have an upstream job) and the main job has no linkage with those builds.

So it boils down to this: is it possible to start a job build and tell it who is its upstream?

3
What do you need from the upstream job: Artifacts? SVN revision? Workspace? - Slav

3 Answers

3
votes

There is Build Result Trigger plugin. It is literally the inverse of Parameterized Trigger Plugin. Instead of triggering downstream jobs, like the latter does, the Build Result Trigger lets your "downstream" jobs watch/monitor the progress of an upstream job, and trigger based on that result.

This way, your "upstream" job is actually not aware of downstream jobs that are watching it.

2
votes

Check out the Groovy Plugin.

It'll let you fire as many jobs as you want, and set the upstream cause.

Code Example: http://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin#Groovyplugin-Retrievingparametersandtriggeringanotherbuild

job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
0
votes

A related post is here: How do I dynamically trigger downstream builds in jenkins?

However, from all the answers that I have read it's clear that using the Groovy/Java class hudson.model.Cause.UpstreamCause(currentBuild) does achieve the goal of programmatically triggering another job, but it does not fully establish an upstream/downstream relationship. When you examine the builds you do not see any upstream/downstream information. The only way to see those is to open the console output of each.