Jenkins CopyArtifact步骤-无法找到用于工件复制的项目 [英] Jenkins CopyArtifact step - Unable to find project for artifact copy

查看:753
本文介绍了Jenkins CopyArtifact步骤-无法找到用于工件复制的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于本文尝试在我的环境中测试管道代码.但是它给下面的错误信息.如何修复他的管道代码?

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

如何可以在管道(jenkinsfile)中使用Jenkins Copy Artifacts插件吗?

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

推荐答案

不是使用projectName: '${JOB_NAME}',而是使用projectName: env.JOB_NAME. IE.您完整的复制工件步骤如下所示:

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)
)

这篇关于Jenkins CopyArtifact步骤-无法找到用于工件复制的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆