Jenkins – Parameterized Trigger and Copy Artifact Guide

Jenkinsrelease

I'm working on setting up Jenkins to handle our release builds. A release build consists of a Windows installer that includes some binaries that must be built on Linux.

Here's what I have so far:

  • The Windows portion and Linux portion are set up as separate Jenkins projects.
  • The Windows project is parameterized, taking the Subversion tag to build and release.
  • As part of its build, the Windows project triggers a build of that same Subversion tag for the Linux project (using the Parameterized Trigger plugin) then copies the artifacts from the Linux project (using the Copy Artifact plugin) to the Windows project's workspace so that they can be included in the Windows installer.

Where I'm stuck: Right now, Copy Artifact is set up to copy the last successful build. It seems more robust to configure Copy Artifact to copy from the exact build that Parameterized Trigger triggered, but I'm having trouble figuring out how to make that work. There's an option for a "build selector" parameter that I think is intended to help with this, but I can't figure out how it's supposed to be set up (and blindly experimenting with different possibilities is somewhat painful when the build takes an hour or two to find success or failure).

How should I set this up? How does build selector work?

Best Answer

After you've completed a triggered build you'll have a new env variable set to the build number of that triggered build called TRIGGERED_BUILD_NUMBER_<job name>. You can use that to specifically copy back the artifacts:

  1. Windows build (called "WindowsBuild"), calls the Linux build (called "LinuxBuild") using the Parameterized Trigger plugin.

    You've got this part, just make sure to check Block until the triggered projects finish their builds and fail the build of course if the Linux build fails.

  2. Next in your Copy Artifacts from another project step:

    Project name: LinuxBuild

    Which build: Specific build

    Build number: $TRIGGERED_BUILD_NUMBER_LinuxBuild (All Project names have characters not a-zA-Z or 0-9 replaced by _ ; multiple characters are condensed into a single _).