How to wait for user input in a Declarative Pipeline without blocking a heavyweight executor

前端 未结 5 826
执念已碎
执念已碎 2021-02-05 03:25

I\'m rebuilding an existing build pipeline as a jenkins declarative pipeline (multi-branch-pipeline) and have a problem handling build propagation.

After packaging and s

5条回答
  •  醉酒成梦
    2021-02-05 03:57

    See best practice 7: Don’t: Use input within a node block. In a declarative pipeline, the node selection is done through the agent directive.

    The documentation here describes how you can define none for the pipline and then use a stage-level agent directive to run the stages on the required nodes. I tried the opposite too (define a global agent on some node and then define none on stage-level for the input), but that doesn't work. If the pipeline allocated a slave, you can't release the slave for one or more specific stages.

    This is the structure of our pipeline:

    pipeline {
      agent none
      stages {
        stage('Build') {
          agent { label 'yona' }
          steps {
            ...
          }
        }
        stage('Decide tag on Docker Hub') {
          agent none
          steps {
            script {
              env.TAG_ON_DOCKER_HUB = input message: 'User input required',
                  parameters: [choice(name: 'Tag on Docker Hub', choices: 'no\nyes', description: 'Choose "yes" if you want to deploy this build')]
            }
          }
        }
        stage('Tag on Docker Hub') {
          agent { label 'yona' }
          when {
            environment name: 'TAG_ON_DOCKER_HUB', value: 'yes'
          }
          steps {
            ...
          }
        }
      }
    }
    

    Generally, the build stages execute on a build slave labeled "yona", but the input stage runs on the master.

提交回复
热议问题