1
votes

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:

  • While I can't configure the Copy Artifact permission via the configuration UI for the MB-pipeline, the option is accepted and should work.
  • The examples I can find would use projectName: 'my-upstream-project/tag-name' as that's the actual job. I don't have a fixed branch or tag, though.

How can I correctly access the upstream artifact?

1

1 Answers

3
votes

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