问题
Based on this post trying to test the pipe line code in my enviroment. But its giving below error message. how to fix his pipeline code?
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'
}
}
}
}
回答1:
Rather than using projectName: '${JOB_NAME}'
, what worked for me is using projectName: env.JOB_NAME
. I.e. your complete copy-artifacts step would look like this:
step([ $class: 'CopyArtifact',
filter: 'test.zip',
projectName: env.JOB_NAME,
fingerprintArtifacts: true,
selector: [$class: 'SpecificBuildSelector', buildNumber: env.BUILD_NUMBER]
])
Or using the more modern syntax:
copyArtifacts(
filter: 'test.zip',
projectName: env.JOB_NAME,
fingerprintArtifacts: true,
selector: specific(env.BUILD_NUMBER)
)
回答2:
If you enable authorization(like rbac), you must grant permission 'Copy Artifact' to the project. In project configuration, General -> Permission to Copy Artifact, check the box and set the projects that can copy the artifact
来源:https://stackoverflow.com/questions/48834762/jenkins-copyartifact-step-unable-to-find-project-for-artifact-copy