基于这篇文章试图在我的环境中测试管道代码。但它给出了以下错误消息。如何修复他的管道代码?
ERROR: Unable to find project for artifact copy: test
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
Finished: FAILURE
How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?
pipeline {
agent any
stages {
stage ('push artifact') {
steps {
sh '[ -d archive ] || mkdir archive'
sh 'echo test > archive/test.txt'
sh 'rm -f test.zip'
zip zipFile: 'test.zip', archive: false, dir: 'archive'
archiveArtifacts artifacts: 'test.zip', fingerprint: true
}
}
stage('pull artifact') {
steps {
sh 'pwd'
sh 'ls -l'
sh 'env'
step([ $class: 'CopyArtifact',
filter: 'test.zip',
projectName: '${JOB_NAME}',
fingerprintArtifacts: true,
selector: [$class: 'SpecificBuildSelector', buildNumber: '${BUILD_NUMBER}']
])
unzip zipFile: 'test.zip', dir: './archive_new'
sh 'cat archive_new/test.txt'
}
}
}
}
答案 0 :(得分:1)
如果启用授权(例如rbac),则必须授予权限'复制工件'到项目。在项目配置中,常规 - >复制工件的权限,选中复选框并设置可复制工件的项目
答案 1 :(得分:1)
对我有用的是使用projectName: '${JOB_NAME}'
,而不是使用projectName: env.JOB_NAME
。即您完整的复制工件步骤将如下所示:
step([ $class: 'CopyArtifact',
filter: 'test.zip',
projectName: env.JOB_NAME,
fingerprintArtifacts: true,
selector: [$class: 'SpecificBuildSelector', buildNumber: env.BUILD_NUMBER]
])
或者使用更现代的语法:
copyArtifacts(
filter: 'test.zip',
projectName: env.JOB_NAME,
fingerprintArtifacts: true,
selector: specific(env.BUILD_NUMBER)
)