How to Copy Artifacts from other Jenkins Job from a Pipeline?

Viewed 9074

I want to copy a build artifact from another Jenkins Job using the CopyArtifact plugin.

The artifact is created using the following command:

archiveArtifacts artifacts: '_Builds/BuildRelease/**', fingerprint: true
build 'Release Installer'

Within the 'Release Installer' job, I try the obtain the archived artifacts using the following command within the Pipeline:

  stages {
    stage('Get Artifacts') {
        steps {
            step([  $class: 'CopyArtifact',
                    projectName: "MyBuildJob",
                    filter: "_Builds/BuildRelease/archive.zip"
            ])
        }
    }

When the "Release Installer" Job is executed, the artifact is not found. Both jobs are executed on the same Build node.

I think my filter rule is missing something. Unfortunately the available Jenkins documentation is a little thin on details and examples.

1 Answers

I believe that the default is to copy from the last successful job. However, it looks like you currently want the upstream job. Here is a snippet:

copyArtifacts fingerprintArtifacts: true, projectName: 'MyBuildJob', selector: upstream()

I generated this code using the snippet generator. It should exist on the left panel of the classic view of a job. The button text reads "Pipeline Syntax" and the url is "my.jenkins.instance.com/pipeline-syntax/"

Specifying an artifact filter is not required, it will copy all of them. However if you want to keep the filter:

copyArtifacts filter: '_Builds/BuildRelease/archive.zip', fingerprintArtifacts: true, projectName: 'MyBuildJob', selector: upstream()
Related