jenkinsfile copyArtifacts失败

时间:2019-02-22 22:45:24

标签: jenkins continuous-integration jenkins-pipeline

我已经安装了Copy Artifact插件,并尝试通过jenkinsfile通过以下Jenkinsfile进行构建和部署

参数DEPLOY_BUILD_NUMBER默认为当前内部版本号。如果DEPLOY_BUILD_NUMBER是当前内部版本号,或者只是部署为DEPLOY_BUILD_NUMBER指定的任何内部版本号,我都希望采用这种方式来构建和部署管道

pipeline {
    agent { label 'windows' }

    parameters {
        string(
            name: 'DEPLOY_BUILD_NUMBER',
            defaultValue: '${BUILD_NUMBER}',
            description: 'Fresh Build and Deploy OR Deploy Previous Build Number'
        )
    }

    stages {
        stage ('Build') {
            steps {
                echo "Building"
            }
            post {
                success {
                    archiveArtifacts artifacts: 'build.tar.gz', fingerprint: true
                }
            }
        }
        stage ('Deploy') {
            steps {
                echo "Deploying...."
                script {
                    step ([$class: 'CopyArtifact',
                    projectName: '${JOB_NAME}',
                    filter: "*.tar.gz"]);
                }
            }
        }
    }
    post {
        always {
            cleanWs()
        }
    }
}

运行此管道时,出现以下错误

java.lang.UnsupportedOperationException: no known implementation of interface jenkins.tasks.SimpleBuildStep is named CopyArtifact

也尝试过

stage ('Deploy') {
        steps {
            echo "Deploying...."
            copyArtifacts filter: '*.tar.gz', fingerprintArtifacts: true, projectName: '${JOB_NAME}'
        }
    }

因以下错误而失败

java.lang.NoSuchMethodError: No such DSL method 'copyArtifacts' found among steps

stage ('Deploy') {
    steps {
        echo "Deploying...."
        script {
                copyArtifacts filter: '*.tar.gz', fingerprintArtifacts: true, projectName: '${JOB_NAME}'
            }
    }
}

这给了我

java.lang.NoSuchMethodError: No such DSL method 'copyArtifacts' found among steps

copyArtifacts的正确语法是什么?我在这里想念的是什么?

2 个答案:

答案 0 :(得分:1)

CopyArtifact定义了一个步骤copyArtifacts,您可以直接使用它。

查看步骤参考here

答案 1 :(得分:0)

我将检查您已安装的复制工件插件的版本(您可以在/ pluginManager / installed中看到),支持管道的最低版本为1.39