0

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.

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • 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{}` blocks – Patrice M. Sep 16 '20 at 18:22

1 Answers1

1

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

Isaiah4110
  • 9,855
  • 1
  • 40
  • 56
  • You're using declarative pipelines, while mine are scripted though, if that makes a difference. I'm very sure I'm using the correct job name in my second pipeline. I just copy/paste the "Full project name" displayed at the top of my Pipeline1 onto my Pipeline2. – Chris F Sep 16 '20 at 15:51
  • 1
    My bad, I had a typo in the project name. – Chris F Sep 16 '20 at 16:00