1

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?

Amir Katz
  • 643
  • 2
  • 10
  • 23

3 Answers3

3

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.

Slav
  • 27,057
  • 11
  • 80
  • 104
  • Thanks, but I **do** need the upstream job to be aware of the children and it needs to wait until they all complete. Good to know, but not suitable for my problem. – Amir Katz Aug 17 '14 at 15:43
  • Then what problem are you having triggering multiple downstream projects? – Slav Aug 18 '14 at 13:35
  • please see my most recent comment where I explain what is my problem and why using Groovy code does not completely solve it. – Amir Katz Aug 21 '14 at 11:08
2

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))
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
0

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.

Community
  • 1
  • 1
Amir Katz
  • 643
  • 2
  • 10
  • 23