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

前端 未结 5 820
执念已碎
执念已碎 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:48

    I know this thread is old, but I believe a solution to the "Edit 2" issue, besides stashing, is to use nested stages.

    https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/#running-multiple-stages-with-the-same-agent-or-environment-or-options

    According to this page:

    ... if you are using multiple agents in your Pipeline, but would like to be sure that stages using the same agent use the same workspace, you can use a parent stage with an agent directive on it, and then all the stages inside its stages directive will run on the same executor, in the same workspace.

    Here is the example provided:

    pipeline {
        agent none
    
        stages {
            stage("build and test the project") {
                agent {
                    docker "our-build-tools-image"
                }
                stages {
                   stage("build") {
                       steps {
                           sh "./build.sh"
                       }
                   }
                   stage("test") {
                       steps {
                           sh "./test.sh"
                       }
                   }
                }
                post {
                    success {
                        stash name: "artifacts", includes: "artifacts/**/*"
                    }
                }
            }
    
            stage("deploy the artifacts if a user confirms") {
                input {
                    message "Should we deploy the project?"
                }
                agent {
                    docker "our-deploy-tools-image"
                }
                steps {
                    sh "./deploy.sh"
                }
            }
        }
    }
    

提交回复
热议问题