Pipeline - production - input in the stage

17 views
Skip to first unread message

zakyn

unread,
Jun 16, 2019, 11:13:38 AM6/16/19
to Jenkins Users
Hello,

I would like to ask you for your help.

I am trying to declare this workflow:
- user has to choose param - dev, test, prod
- when use dev - copy deploy-01.txt
- when use test - copy deploy-02.txt
- when use prodution - user has to write password - when it is correct then - copy both files.

My problem is that when I choose dev, or test, then input from prod is still active (is shown). I just want the message to be shown only if prod is chose in the step 1.

Thank you.

Vladimir


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






Reply all
Reply to author
Forward
0 new messages