管道中的多个Jenkins节点

问题描述 投票:0回答:1

目前我们有一个有4个阶段的詹金斯管道。设置,构建,部署,拆解。部署和拆除提示手动用户输入。因此,我们不希望手动用户输入来执行执行程序。所以,我们想要使用agent none。然而,当恢复时,没有保证我们得到相同的jenkins工作区。 Stash / unstash表示它使用了大量资源,因此如果你有大文件不使用它。有没有办法获得确切的奴隶,并在恢复时,回到同一个奴隶?

我现在有类似的东西,我也在顶级尝试了代理gcp,并且在手动输入中没有代理

pipeline {
agent none

 environment {
    userInput = false
 }

stages {
    stage('Setup') {
        agent { node { label 'gcp' } }
        steps {
            deleteDir()
            dir('pipelines') {
                checkout scm
            }
            dir('deployment_pipelines'){
                git branch: __deployment_scripts_code_branch, credentialsId: 'jenkins', url: __deployment_scripts_code_repo
            }
            dir('gcp_template_core'){
                git branch: __gcp_template_code_branch, credentialsId: 'jenkins', url: __gcp_template_code_repo
            }
            dir('control_repo'){
                 git branch: _control_repo_branch, credentialsId: 'jenkins', url: _control_repo
            }

            // Copy core templates to the project
            sh('bash deployment_pipelines/deployment/setup.sh gcp_template_core/gcp_foundation/ control_repo')
        }
    }

    stage('Build') {
        agent { node { label 'gcp' } }
        steps {
            sh('printenv') //TODO: Remove. Debug only
            sh('python deployment_pipelines/deployment/build.py control_repo --env ${_env_type_long}')
        }
    }

    stage('Deploy') {
        agent { node { label 'gcp' } }
        steps {
            sh('python deployment_pipelines/deployment/deploy.py control_repo --env ${_env_type_short}')
        }
    }

     stage('Release') {
        steps {
            agent none
            script {
                sh('python deployment_pipelines/deployment/set_manual_approvers.py deployment_pipelines/config/production-release-approvers.yaml -o approver.txt')
                def approvers = readFile('approver.txt')

                try {
                    userInput = input(
                        message: 'Do you want to proceed with Release?',
                        submitter: approvers)
                } catch(err) { // input false
                    //def user = err.getCauses()[0].getUser() //need script approval for getUser()
                    userInput = false
                    // echo "Aborted by [${user}]"
                }
                agent { node { label 'gcp' } }
                if(userInput)
                {
                    sh("echo 'Do Release'")
                }
            }
        }
    }
    stage('Teardown'){
        agent { node { label 'gcp' } }
        steps {
             script {
                def approvers = readFile('approver.txt')

                try {
                    userInput = input(
                        message: 'Do you want to proceed with Teardown?',
                        submitter: approvers)
                } catch(err) { // input false
                    //def user = err.getCauses()[0].getUser() //need script approval for getUser()
                    userInput = false
                    // echo "Aborted by [${user}]"
                }
                if(userInput)
                {
                    sh("echo 'Do Teardown'")
                }
            }
        }
    }
}

post {
    always {
        echo 'DO TEARDOWN REGARDLESS'
    }
}
}
jenkins groovy jenkins-pipeline
1个回答
0
投票

agent none不应位于阶段('Release')的步骤块之上。您可以参考https://jenkins.io/doc/book/pipeline/syntax/#agent获取语法和流程

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.