The Secure Copy plugin creates a one way link between two jobs. We will call the job producing the artifacts the Producer, and the job that will consume the artifacts the Consumer.
The Producer job must be configured to archive the artifacts to be shared.
For jobs using the Maven job type, if the Maven lifecycle is advanced to a phase on or after the “package” phase, all the artifacts that are attached to the Maven reactor will be automatically archived by the Jenkins job.
Note
Do not confuse a Maven project built using a Freestyle job type and a Maven Build Step with a Maven project built using a Maven job type. The first does not have automatic archiving of artifacts, while the second does.
For all other job types (e.g. Freestyle, Matrix, etc), it is necessary to configure the “Archive Artifacts” publisher.
Note
A Maven project built with a Freestyle job type will need the ”Archive Artifacts” publisher configured.
The Producer job will also need the appropriate permalink which is used to select the build from which the artifacts will be copied. Jenkins comes with a number of built-in permalinks:
- Last build - the most recent build. This is rarely useful, as it can include a currently running build.
- Last stable build - the most recent stable build. Usually a good choice.
- Last successful build - the most recent successful build. A good choice if you can accept artifacts from builds with test failures.
- Last failed build - the most recent failed build. Probably not useful unless implementing some sort of automated failure analysis.
- Last unstable build - the most recent unstable build. Again rarely useful.
- Last unsuccessful build - the most recent unsuccessful build. Again rarely useful.
In addition, Jenkins plugins can define their own permalinks. For example, the “Promoted builds” plugin defines a permalink for each promotion process.
Creating an exported permalink starts with adding an “Import artifacts from an exported permalink” build step to the Consumer job. See Figure 16.1, “Adding the “Import artifacts from an exported permalink”” and Figure 16.2, “After adding the “Import artifacts from an exported permalink””
When the build step has been added, a random key will be generated. This key will be provided to the Producer job, which will generate a secret to be given to the Consumer job.
Note
If the Producer and Consumer jobs are on the same Jenkins instance, or if you are navigating away from the Consumer job’s configure screen, be sure to save the configuration after adding the build step. The key is generated when the build step is added, and if the job is not saved, the next time the build step is added a new key will be generated.
On the Producer job navigate to the “Exports” screen (Figure 16.3, “The exported permalinks screen”) and select the “Create” option. Enter the key from the Consumer job (Figure 16.4, “Creating an exported permalink”) and select the permalink (Figure 16.5, “Selecting the permalink to export”). Click on the “Create” button to generate the secret (Figure 16.6, “An exported permalink with generated secret”).
On the Consumer job’s configure screen enter the secret generated by the Producer job (Figure 16.7, “A fully configured “Import artifacts from an exported permalink” build step”) along with any other configuration options, such as:
- An Apache Ant-style glob pattern to select a subset of artifacts to copy.
- The target directory into which the artfacts should be copied.
- Whether to flatten any directory structure information from the Producer job.
- Whether this build step is optional; if not, the Consumer build will be marked as failed if there are no artifacts to copy.