pipeline{
agent any
parameters {
choice choices: ['dev', 'testers', 'prod'], description: 'Select to which deploy-to', name: 'deploy-to'
}
stages{
stage('Clean WS'){
steps{
cleanWs deleteDirs: true, patterns: [[pattern: '**/*.hg/**', type: 'EXCLUDE']]
}
}
stage('when'){
stages{
stage('Copy Archive - build-01') {
when {
environment ignoreCase: true, name: 'deploy-to', value: 'dev'
beforeAgent true
}
steps {
script {
step ([$class: 'CopyArtifact',
projectName: 'build-01',
filter: "*.*",
target: 'build-01']);
}
}
}
stage('Copy Archive - build-02') {
when {
environment ignoreCase: true, name: 'deploy-to', value: 'test'
beforeAgent true
}
steps {
script {
step ([$class: 'CopyArtifact',
projectName: 'build-02',
filter: "*.*",
target: 'build-02']);
}
}
}
}
}
stage('Production'){
stages{
stage('Copy Archive - build-01 and build-02') {
when {
environment ignoreCase: true, name: 'deploy-to', value: 'prod'
beforeAgent true
}
input {
message 'Are you sure that you would like to deploy to production?'
id 'ProdDeployment'
ok 'Are you sure'
submitter 'any'
parameters {
password defaultValue: 'No', description: 'Password to production', name: 'Password-to-production'
}
}
steps {
// here I will check the Password-to-production
script {
step ([$class: 'CopyArtifact',
projectName: 'build-01',
filter: "*.*",
target: 'build-01']);
}
script {
step ([$class: 'CopyArtifact',
projectName: 'build-02',
filter: "*.*",
target: 'build-02']);
}
}
}
}
}
}
post{
always{
archiveArtifacts '**/*.txt'
}
}
}