Raphael
Raphael

Reputation: 10589

Copy artifacts from an upstream multi-branch pipeline

I have the following Jenkins setup:

  1. A multi-branch pipeline which sometimes (on certain tag builds) triggers
  2. a pipeline that builds an installer from the upstream artifacts.

In the upstream MB-pipeline, I have the following fragments:

options {
    copyArtifactPermission('my-downstream-project');
}

post {
   success {
       script {
           if (isRelease()) {
               build job: 'my-downstream-project'
           }
       }
   }
}

The downstream pipeline, I then try to grab the artifacts:

copyArtifacts projectName: 'my-upstream-project', 
              selector: upstream(),
              filter: '*.jar',
              fingerprintArtifacts: true

While the downstream build is started, it fails with:

ERROR: Unable to find project for artifact copy: hds-access-code-cache This may be due to incorrect project name or permission settings; see help for project name in job configuration.

My understanding so far:

How can I correctly access the upstream artifact?

Upvotes: 2

Views: 4542

Answers (1)

Raphael
Raphael

Reputation: 10589

It is possible to pass down the job name as parameter.

Change the upstream pipeline to:

build job: 'my-downstream-project',
      parameters: [string(name: 'upstreamJobName', value: env.BRANCH_NAME)]

Add the parameter to the downstream pipeline:

parameters { 
    string(name: 'upstreamJobName', 
        defaultValue: '', 
        description: 'The name of the job the triggering upstream build'
    )
}

And change the copy directive to:

copyArtifacts projectName: "my-upstream-project/${params.upstreamJobName}", 
              selector: upstream(),
              filter: '*.jar',
              fingerprintArtifacts: true

Et voila:

Copied 1 artifact from "My Upstream Project » my-tag" build number 1

Upvotes: 4

Related Questions