在Jenkins管道之间共享文件
我看到的许多示例都类似于在同一管道中共享一个文件。我想在两个不同的管道之间共享一个文件 我试着像这样使用复制工件插件在Jenkins管道之间共享文件,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我看到的许多示例都类似于在同一管道中共享一个文件。我想在两个不同的管道之间共享一个文件 我试着像这样使用复制工件插件 Pipeline1: node {'linux-0') { stage("Create file") { sh "echo \"hello world\" > hello.txt" archiveArtifacts artifact: 'hello.txt', fingerprint: true
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
我错过了什么
注意:我真正的脚本化管道(即非声明性管道)比这些管道更复杂,因此我无法将它们转换为声明性管道。我刚刚测试了这一点,它对我来说运行良好。这是我的代码pipeline1:
pipeline {
agent any
stages {
stage('Hello') {
steps {
sh "echo \"hello world\" > hello.txt"
archiveArtifacts artifacts: 'hello.txt', fingerprint: true
}
}
}
}
管道2
pipeline {
agent any
stages {
stage('Hello') {
steps {
copyArtifacts projectName: 'pipeline1',
fingerprintArtifacts: true,
filter: 'hello.txt'
}
}
}
}
copyArtifacts项目名称:“pipeline1”
确保项目名称与第一条管线的名称完全相同(
在该名称上没有冲突)。如果您有冲突或使用文件夹插件,请确保查看此链接以相应地引用项目:
您使用的是声明性管道,而我的管道是脚本化的,如果这有区别的话。我非常确定我在第二条管道中使用了正确的工作名称。我只是将管道顶部显示的“完整项目名称”复制/粘贴到管道2上。糟糕的是,我在项目名称中输入了一个拼写错误。前提有点偏离。使用
copyArtifacts
在不同管道之间共享文件,使用stash/unstash
在同一管道实例中共享文件,即在不同的节点{}
块之间共享文件