0
votes

A lot of the examples I see like How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)? share a file within the SAME pipeline. I want to share a file between two different pipelines.

I tried to use the Copy Artifacts plugin like so

Pipeline1:
node {'linux-0') {
  stage("Create file") {
    sh "echo \"hello world\" > hello.txt"
    archiveArtifacts artifact: 'hello.txt', fingerprint: true
  }
}

Pipeline2:
node('linux-1') {
    stage("copy") {
        copyArtifacts projectName: 'Pipeline1',
                      fingerprintArtifacts: true,
                      filter: 'hello.txt'
    }
}

and I get the following error for Pipeline2

ERROR: Unable to find project for artifact copy:  Pipeline1
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
Finished: FAILURE

What am I missing?

NOTE: My real scripted, i.e., not declarative, pipelines are more complicated than these so I can't readily convert them to declarative pipelines.

1
The premise is a bit off. Use copyArtifacts to share files between different pipelines, use stash/unstash to share files within the same pipeline instance, i.e. between different node{} blocksPatrice M.

1 Answers

1
votes

I just tested this and it worked fine for me. Here is my code, pipeline1:

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                sh "echo \"hello world\" > hello.txt"
                archiveArtifacts artifacts: 'hello.txt', fingerprint: true
            }
        }
    }
}

pipeline2

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                copyArtifacts projectName: 'pipeline1',
                      fingerprintArtifacts: true,
                      filter: 'hello.txt'
            }
        }
    }
}

copyArtifacts projectName: 'pipeline1'

Ensure that the project name is exactly same as the first pipleline's name ( and there are no conflicts on that name). If you have conflicts or use folder plugin ensure to look at this link to refer the project accordingly:

https://wiki.jenkins.io/display/JENKINS/How+to+reference+another+project+by+name