jenkins the definitive guide

(Jeff_L) #1

When the user selects a particular build job, the build number will also be stored in
the environment variables for use in the build steps. The environment variable is called
COPYARTIFACT_BUILD_NUMBER_MY_BUILD_JOB, where MY_BUILD_JOB is the name of the original
build job (in upper case and with characters other than A–Z converted to underscores). For
example, if we copy an artifact from build number 4 of the gameoflife-default project, the
COPYARTIFACT_BUILD_NUMBER_GAMEOFLIFE_DEFAULT environment variable would be set to 4.


The second part of the configuration is to tell Jenkins what to fetch, and from which build job. In the
Build section of our project configuration, we add a “Copy artifacts from another project” step. Here
you specify the project where the artifact was built and archived (gameoflife-default in our example).
You also need to make Jenkins use the build specified in the parameter we defined earlier. You do this
by choosing “Specified by a build parameter” in the “Which build” option, and providing the variable
name we specified earlier in the build selector name field (see Figure 12.6, “Specify where to find the
artifacts to be deployed”). Then, just configure the artifacts to copy as we did in the previous example.


Figure 12.6. Specify where to find the artifacts to be deployed


Finally, we deploy the copied artifact using the Deploy plugin, as illustrated in Figure 12.3, “Deploying
to Tomcat using the Deploy Plugin”.


So let’s see how this build works in practice. When we kick off a build manually, Jenkins will propose a
list of options letting you select the build to redeploy (see Figure 12.7, “Choosing the build to redeploy”).


Figure 12.7. Choosing the build to redeploy

Free download pdf