• Pipeline - December

      Problem
      If an input is used within a stage that uses an agent, it will block the agent from being used until the input proceeds.

      stage('rollback') {
        agent {
          label 'deployer-agent'
        }
        steps {
          input 'should I rollback?' // blocks agent 'deployer-agent'
        }
      }
      

      Solution
      Introduce a input directive inside stage that blocks the stage from executing and acquiring the agent.

      stage('rollback') {
        input {
          message 'should I rollback?'
        }
        agent {
          label 'deployer-agent'
        }
        steps {
          echo 'deploying'
        }
      }
      

      This would be the same in scripted pipeline:

      stage('rollback') {
        input 'should I rollback?'
        node ('deployer-agent') {
          echo 'deploying'
        }
      }
      

      Full Syntax

      input {
        // Parameters are all the same as the input step. Only message is required.
        message "Should we continue?"
        id "some-id" // optional, defaults to stage name.
        ok "For the OK button"
        submitter "alice,bob"
        submitterParameter "approver"
        parameters {
          // Same syntax as top-level parameters block
          booleanParam(name: 'someParam', defaultValue: true, description: 'some description')
          ...
        }
      }
      

          [JENKINS-48379] Input/parameters for Stages

          Rafael Pestano added a comment - - edited

          Hi guys, I'm using pipeline decçarative (and pipeline model api) v1.2.7 and am using the input directive on a stage like below:

          pipeline { 
              agent any
              tools { 
                  maven 'Maven 3.3.9' 
                  jdk 'jdk1.8' 
              }
              
              stages {    
                  stage("Build") {
                      steps {
                          sh 'mvn clean package'
                      }
                  }  
                  
                  stage("Ir para produção?") {
                      input {
                          message "Aprovar o deploy?"
                          ok "Sim"
                      }
                      agent {
                          label 'master'
                      }
                      steps {
                          deploy ambiente: 'DES-7.0', grupo: 'APM'
                      }
                  }
                  
              
             }//fim stages  
          }  

          but a Jenkins executor is being alocated. I thought this issue would fix this.

          In image "agent-blocked.png" attached you can see a job queued (waiting for executor) and one executing the pipeline above (waiting for manual approval).

          Jenkins v2.89.3
          Pipeline declarative v1.2.7

          Rafael Pestano added a comment - - edited Hi guys, I'm using pipeline decçarative (and pipeline model api) v1.2.7 and am using the input directive on a stage like below: pipeline { agent any tools { maven 'Maven 3.3.9' jdk 'jdk1.8' } stages { stage("Build") { steps { sh 'mvn clean package' } } stage("Ir para produção?") { input { message "Aprovar o deploy?" ok "Sim" } agent { label 'master' } steps { deploy ambiente: 'DES-7.0', grupo: 'APM' } } }//fim stages } but a Jenkins executor is being alocated. I thought this issue would fix this. In image "agent-blocked.png" attached you can see a job queued (waiting for executor) and one executing the pipeline above (waiting for manual approval). Jenkins v2.89.3 Pipeline declarative v1.2.7

          Rafael Pestano added a comment - - edited

          Alright, got it working, the pipeline must run with agent 'none' and then each stage must declare it's agent:

          pipeline { 
              agent none //important
              tools { 
                  maven 'Maven 3.3.9' 
                  jdk 'jdk1.8' 
              }
              
              stages {            
                  stage("Build") {
                      agent any
                      steps {
                          sh 'mvn clean package'
                      }
                  }  
                  stage("Ir para produção?") {
                      input {
                          message "Aprovar o deploy?"
                          ok "Sim"
                      }
                      agent  any //must be declared after input directive
                      steps {
                        deploy ambiente: 'DES-7.0', grupo: 'APM' 
                      }
                  }
                     
             }//end stages  
          }  
          

          Rafael Pestano added a comment - - edited Alright, got it working, the pipeline must run with agent 'none' and then each stage must declare it's agent: pipeline { agent none //important tools { maven 'Maven 3.3.9' jdk 'jdk1.8' } stages { stage("Build") { agent any steps { sh 'mvn clean package' } } stage("Ir para produção?") { input { message "Aprovar o deploy?" ok "Sim" } agent any //must be declared after input directive steps { deploy ambiente: 'DES-7.0', grupo: 'APM' } } }//end stages }

          Torsten Kleiber added a comment - - edited

          But when I need a timeout around the input step, I must use this inside step and the executor is blocked again. So we need timeout too in stage.

          My requirement is, that when a deployment is not proceeded in a defined time, the the pipeline has to be cancelled.

          Torsten Kleiber added a comment - - edited But when I need a timeout around the input step, I must use this inside step and the executor is blocked again. So we need timeout too in stage. My requirement is, that when a deployment is not proceeded in a defined time, the the pipeline has to be cancelled.

          Hi tkleiber,

          I haven't tried but last version of declarative pipeline (1.2.8) states it supports input and timeout outside steps, see here: https://jenkins.io/blog/2018/04/09/whats-in-declarative/

          Lastly, you can use timeout in the stage options, as mentioned above, to time-out the input if too much time has passed without a response.

          Rafael Pestano added a comment - Hi tkleiber , I haven't tried but last version of declarative pipeline (1.2.8) states it supports input and timeout outside steps, see here: https://jenkins.io/blog/2018/04/09/whats-in-declarative/ Lastly, you can use timeout in the stage options, as mentioned above, to time-out the input if too much time has passed without a response.

          Thanks I have bookmarked this, but not read before. Stage timeouts seems what I need!

          Torsten Kleiber added a comment - Thanks I have bookmarked this, but not read before. Stage timeouts seems what I need!

          Just tested and is working great:

          pipeline {
          
           agent none
          
           stages {
          
              stage("deploy to production ") {
                      options {
                          timeout(time: 1, unit: 'DAYS')
                      }
                      input {
                          message "Approve deploy?"
                          ok "Yes"
                      }
                      agent  any //must be declared after input directive
                      steps {
                        deploy env: 'PRODUCTION' 
                      }
                  }
          
             }//end stages
          
             post {
                  always {
                       node('master') { //important because the pipeline agent is none and some plugins may need to access the workspace
                           lastChanges()
                       }
                  }
              }  
          
          } //end pipeline
          

          Rafael Pestano added a comment - Just tested and is working great: pipeline { agent none stages { stage( "deploy to production " ) { options { timeout(time: 1, unit: 'DAYS' ) } input { message "Approve deploy?" ok "Yes" } agent any //must be declared after input directive steps { deploy env: 'PRODUCTION' } } } //end stages post { always { node( 'master' ) { //important because the pipeline agent is none and some plugins may need to access the workspace lastChanges() } } } } //end pipeline

          Michael Neale added a comment -

          nice - tkleiber should add this to docs!

          Michael Neale added a comment - nice - tkleiber should add this to docs!

          Don't understand - what do you mean by this?

          Torsten Kleiber added a comment - Don't understand - what do you mean by this?

          Michael Neale added a comment -

          tkleiber oh just mean that the docs website would ideally cover this feature (if it doesn't already) - nothing more than that. 

          Michael Neale added a comment - tkleiber oh just mean that the docs website would ideally cover this feature (if it doesn't already) - nothing more than that. 

          Liam Newman added a comment -

          Bulk closing resolved issues.

          Liam Newman added a comment - Bulk closing resolved issues.

            abayer Andrew Bayer
            jamesdumay James Dumay
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: