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

Input/parameters for Stages

    XMLWordPrintable

Details

    • Pipeline - December

    Description

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

      Attachments

        Issue Links

          Activity

            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
            
            rmpestano 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
            michaelneale Michael Neale added a comment -

            nice - tkleiber should add this to docs!

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

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

            tkleiber Torsten Kleiber added a comment - Don't understand - what do you mean by this?
            michaelneale 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. 

            michaelneale 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. 
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

            People

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

              Dates

                Created:
                Updated:
                Resolved: