Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve build number or artifacts of downstream build in Jenkins

I have a job (call it BIGJOB) in Jenkins; several of the build steps are to trigger builds on other jobs (call them SMALLJOB) using the Parameterized Trigger Plugin then wait for them to complete. What I need to do is retrieve artifacts from the triggered build on SMALLJOB.

Originally, I thought I could use the Copy Artifact Plugin to retrieve the artifacts from the "last build" of the triggered SMALLJOB. And this does work reliably when there is only one SMALLJOB running at a time.

But I've got multiple BIGJOBs running, all triggering multiple SMALLJOBs so that using the "last build" is unreliable of two SMALLJOBs finish at the same time.

Is there a more reliable way of getting the artifacts from the specific downstream job? If I could just get the build number, I could use curl to get the artifacts.

like image 784
Jason Swager Avatar asked Aug 20 '11 16:08

Jason Swager


People also ask

How do I find my upstream build number?

You can probably find the last build number with groovy in regards to your upstream build, increment it, and assign that value to a dynamic parameter. That means it would be a number generated at build-queue and as long as it's forwarded downstream, should remain the same when needing to reference it.

What is downstream build in Jenkins?

A downstream job is a configured project that is triggered as part of a execution of pipeline. Upstream and downstream jobs help you to configure the sequence of execution for different operations and hence you can orchestrate the flow of execution. We can configure one or more projects as downstream jobs in Jenkins.


1 Answers

Just if any (else) stumples accross this question in the future:

When using the Parameterized Trigger Plugin as a build step, then if the trigger is configured with the "Block until the triggered projects finish their builds" enabled, the following Environment variables are made available for further build steps:

  • LAST_TRIGGERED_JOB_NAME="Last project started"
  • TRIGGERED_BUILD_NUMBER_{project name}="Last build number triggered"

from version 2.17 onwards

  • TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
  • TRIGGERED_BUILD_NUMBERS_{project name}="Comma separated list of build numbers triggered"
  • TRIGGERED_BUILD_RESULT_{project name}="Last triggered build result of project"
  • TRIGGERED_BUILD_RESULT_{project name}RUN{build number}="Result of triggered build for build number"
  • TRIGGERED_BUILD_RUN_COUNT_{project name}="Number of builds triggered for the project"

See more info on the plugin website - linked in the question.

like image 116
tveon Avatar answered Sep 22 '22 05:09

tveon