基于提供的参数的Jenkins管道结帐

时间:2019-04-30 09:38:15

标签: jenkins jenkins-pipeline jenkins-groovy jenkins-declarative-pipeline

我有Jenkins声明性管道,想根据提供的参数签出一个分支

def envToBranch  = [:]
envToBranch['dev'] = 'develop'
envToBranch['stg'] = 'stage'
envToBranch['prod'] = 'master'

pipeline {

  parameters {
    choice(name: 'ENV', choices: ['dev', 'stg', 'prod'], description: 'Application environment')
  }

  stages {
    stage('Checkout') {
      steps {
        checkout([$class: 'GitSCM',
                  branches: [[name: '<how-to-access-mapping-here>']],
                  doGenerateSubmoduleConfigurations: false,
                  extensions: [
                    [$class: 'SparseCheckoutPaths',  sparseCheckoutPaths:[[$class:'SparseCheckoutPath', path:'ansible/']]]
                  ],
                  submoduleCfg: [],
                  userRemoteConfigs: [
                    [credentialsId: 'my-creds',
                    url: 'git@github.com:MyOrg/my-repo.git']
                  ]])
      }
    }
  }
}

那么我如何在checkout指令中访问映射?我可以在script指令中执行相同的操作吗?

0 个答案:

没有答案