Collecting status of downstream jobs

726 views
Skip to first unread message

zerozer...@gmail.com

unread,
May 2, 2016, 7:07:26 PM5/2/16
to Jenkins Users
Hi,
if I have a job triggering other downstream jobs (as build steps), is there a way for the upstream job to get the success/failure status of downstream jobs so that I can insert those results into a final email, sent at the end of the upstream job?

The Parametrized Trigger plugin makes available some variables for this, but their names are based on the downstream job names ("$TRIGGERED_BUILD_RESULT_<jobname>") and I am not able to know the names of all downstream jobs in advance so I cannot easily use those variables.

Any suggestions? This looks like a basic task so I'm sure I must be missing something...
Thank you.

01

zerozer...@gmail.com

unread,
May 11, 2016, 8:21:35 AM5/11/16
to Jenkins Users
Il giorno martedì 3 maggio 2016 01:07:26 UTC+2, zerozer...@gmail.com ha scritto:
 
if I have a job triggering other downstream jobs (as build steps), is there a way for the upstream job to get the success/failure status of downstream jobs so that I can insert those results into a final email, sent at the end of the upstream job?

Replying myself... I solved my problem by using a Groovy Postbuild script (installing the appropriate Jenkins plugin).
I injected a JOBS_RESULTS environment variable into the job, containing the path to a file where to write downstream job results.
Then added a groovy postbuild like this:

-----------------------
// Get list of triggered downstream jobs
def jobs = manager.getEnvVariable("TRIGGERED_JOB_NAMES")
jobslist = jobs.tokenize(",")

// Get output file name from injected variable, open file, overwrite it with header
def resultsFile = manager.getEnvVariable("JOBS_RESULTS")
def fp = new File(resultsFile)
fp.write "RESULTS OF TRIGGERED JOBS:\n\n"

def jobResultVar = ""
def jobResult = ""

jobslist.each {

  // Get name of result variable for triggered job and then get value
  jobResultVar = "TRIGGERED_BUILD_RESULT_" + "$it"
  jobResult = manager.getEnvVariable(jobResultVar)

  fp << "$it: " + jobResult + "\n"

}
-----------------------

Then used the Extended Email plugin to send an email including this macro in the mail body:

${FILE, path="$JOBS_RESULTS"}

The job needs to run on the master, as the groovy script only runs on the master and so the email plugin would not find the file otherwise.

Maybe it can be useful to someone else.

Bye,
01
Reply all
Reply to author
Forward
0 new messages