在Jenkins管道之间共享文件

时间:2020-09-16 15:18:51

标签: jenkins jenkins-pipeline

我看到的许多示例,例如How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?在SAME管道中共享一个文件。我想在两个不同的管道之间共享文件。

我试图像这样使用Copy Artifacts插件

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'
    }
}

我收到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

我想念什么?

注意:我的真实脚本(即非声明性)管道比这些更为复杂,因此我无法轻易将其转换为声明性管道。

1 个答案:

答案 0 :(得分:1)

我刚刚测试了一下,对我来说效果很好。这是我的代码pipeline1:

padding

pipeline2

pipeline {
    agent any

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

copyArtifacts项目名称:“ pipeline1”

确保项目名称与第一个管道名称完全相同( 并且该名称没有冲突)。如果您有冲突或使用文件夹插件,请确保查看此链接以相应地引用该项目:

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