Reputation: 7038
I have Copy Artifact Plugin installed & trying to build and deploy through jenkins pipeline with following Jenkinsfile
Parameter DEPLOY_BUILD_NUMBER
default to current build number. I want to make it such a way pipeline should build and deploy if DEPLOY_BUILD_NUMBER
is current build number OR just deploy whatever build number specified for 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()
}
}
}
When I run this pipeline I get following error
java.lang.UnsupportedOperationException: no known implementation of interface jenkins.tasks.SimpleBuildStep is named CopyArtifact
Also tried
stage ('Deploy') {
steps {
echo "Deploying...."
copyArtifacts filter: '*.tar.gz', fingerprintArtifacts: true, projectName: '${JOB_NAME}'
}
}
which failed with following error
java.lang.NoSuchMethodError: No such DSL method 'copyArtifacts' found among steps
and
stage ('Deploy') {
steps {
echo "Deploying...."
script {
copyArtifacts filter: '*.tar.gz', fingerprintArtifacts: true, projectName: '${JOB_NAME}'
}
}
}
which gave me
java.lang.NoSuchMethodError: No such DSL method 'copyArtifacts' found among steps
What is the correct syntax for copyArtifacts ? what I am missing here ?
Upvotes: 3
Views: 3569
Reputation: 550
You need to wrap it with "script { .. }"
post {
success {
script {
archiveArtifacts artifacts: 'build.tar.gz', fingerprint: true
}
}
}
Upvotes: 0
Reputation: 1283
I would check the version of the Copy Artifacts plugin you have installed (you can see that in /pluginManager/installed), the minimum version that supports pipeline is 1.39
Upvotes: 4
Reputation: 1923
CopyArtifact defines a step, copyArtifacts, that you can use directly.
Check the step reference here
Upvotes: -1