2017-12-06 12 views
0

現在、私たちは4段階のジェンキンスパイプラインを持っています。セットアップ、ビルド、デプロイ、ティアダウン。手動のユーザー入力のためのDeploy and Teardownプロンプトこのため、手動のユーザー入力がエグゼキュータを受け入れることは望ましくありません。したがって、エージェントnoneを使用します。しかし、再開すると、同じジェンキンスワークスペースを取得する必要はありません。 Stash/unstashは、たくさんのリソースを使用しているので、使用しない大きなファイルがあるとします。正確なスレーブを取得する方法はありますか?再開するときに、同じスレーブを元に戻しますか?パイプライン内の複数のJenkinsノード

私は

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

答えて

0

エージェントのどれもが、ステージ(「リリース」)における上記ステップブロックあってはならないトップレベルでこのような何か今私も試したエージェントのGCPを持って、そして手入力でエージェントなしを入れていません。構文とフローについては、https://jenkins.io/doc/book/pipeline/syntax/#agentを参照してください。

関連する問題