Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50880

Create a new option for running when condition before stage input

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Currently, when using the "stage-level" input (here: https://jenkins.io/doc/book/pipeline/syntax/#input) the when condition of the stage is evaluated after the input is gathered.  We should add an option so the when condition is evaluated before the input is gathered. Something like:

      stage('Production Deploy') {
          agent { label 'linux' }
          when {
              branch "master"
              beforeInput  true
          }
          input { message 'Deploy to Production?' }
          steps {
              echo 'Deploying to Production ... '
          }             
      }

       
      Use cases

      • Evaluate the when condition before the input has been gathered.

      In scope

       

        Attachments

          Issue Links

            Activity

            Hide
            tkleiber Torsten Kleiber added a comment -

            We have the same requirement, business case is following:

            • in multibranch pipeline we want to run the build for every branch but
            • deployment should be done only for the master- or hotfix-branches
            • after manual confirmation
            • in other branches the deployment should be skipped without interaction
            Show
            tkleiber Torsten Kleiber added a comment - We have the same requirement, business case is following: in multibranch pipeline we want to run the build for every branch but deployment should be done only for the master- or hotfix-branches after manual confirmation in other branches the deployment should be skipped without interaction
            Hide
            ennef Christopher Fenner added a comment -

            We have the same requirement:

            • run a stage with input only for specific branches
            Show
            ennef Christopher Fenner added a comment - We have the same requirement: run a stage with input only for specific branches
            Hide
            opa Vincent Letarouilly added a comment - - edited

            I found a workaround, just put your input directive inside the steps one like that

             

            stage('Production Deploy') {
                agent { label 'linux' }
                when {
                    branch "master"
                }
                steps {
                    input { message 'Deploy to Production?' }
                    echo 'Deploying to Production ... '
                }             
             }
            

             

            Show
            opa Vincent Letarouilly added a comment - - edited I found a workaround, just put your input directive inside the steps one like that   stage( 'Production Deploy' ) {     agent { label 'linux' }    when {      branch "master" }     steps { input { message 'Deploy to Production?' } echo 'Deploying to Production ... ' }              }  
            Hide
            tkleiber Torsten Kleiber added a comment -

            This workaround blocks an executor for the time waiting for input. Following is wanted (as described in https://jenkins.io/blog/2018/04/09/whats-in-declarative/)

             

            pipeline {
                agent none // no executor is blocked 
                stages {
                    stage('Production Deploy') {
                        when {
                            branch 'master'
                            // beforeInput: true
                        }
                        input { 
                            message 'Deploy to Production?' // For this input can be waited several days
                        }
                        agent any // From here on for executing the steps an executor is needed
                        steps {
                            echo 'Deploying to Production ... '
                        }
                    }
                }
            }
            
            Show
            tkleiber Torsten Kleiber added a comment - This workaround blocks an executor for the time waiting for input. Following is wanted (as described in https://jenkins.io/blog/2018/04/09/whats-in-declarative/)   pipeline { agent none // no executor is blocked stages { stage( 'Production Deploy' ) { when { branch 'master' // beforeInput: true } input { message 'Deploy to Production?' // For this input can be waited several days } agent any // From here on for executing the steps an executor is needed steps { echo 'Deploying to Production ... ' } } } }
            Hide
            abayer Andrew Bayer added a comment -

            This’ll be in 1.3.3

            Show
            abayer Andrew Bayer added a comment - This’ll be in 1.3.3
            Hide
            johanrydstrom Johan Rydström added a comment -

            Looks good!

            Q: Can I, and if so how can I make the result of the captured input (the approver) available in a variable?

            Show
            johanrydstrom Johan Rydström added a comment - Looks good! Q: Can I, and if so how can I make the result of the captured input (the approver) available in a variable?
            Hide
            tkleiber Torsten Kleiber added a comment -

            Thanks, works as requested.

            Show
            tkleiber Torsten Kleiber added a comment - Thanks, works as requested.

              People

              • Assignee:
                jtaboada Jose Blas Camacho Taboada
                Reporter:
                elkins Erik Elkins
              • Votes:
                9 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: