Jenkins Git分支选择与后备

Sof*_*ose 5 git github bitbucket jenkins jenkins-plugins

在我的项目中,我有一个GitFlow风格的存储库.

如何让Jenkins执行以下操作:(XXXX = Release No)

  1. 构建Release-XXXX分支
  2. 如果不存在发布分支,请构建主分支.

我知道我可以使用git-chooser-alternative插件按优先顺序放置分支,但我不知道如何选择包含单词Release的分支 -

Tom*_*rre 1

您可以为此使用管道。

def doCheckout(cloneUrl,branches) {
 for (String branch : branches) {
  try {
   deleteDir()
   sh 'git config --global credential.helper cache'
   checkout([
    $class: 'GitSCM',
    branches: [[name: branch]],
    extensions: [
     [$class: 'CloneOption',
      noTags: false,
      reference: '',
      shallow: true,
      honorRefspec: true],
     [$class: 'WipeWorkspace'],
     [$class: 'CleanBeforeCheckout']
    ],
    submoduleCfg: [],
    userRemoteConfigs: [
     [ credentialsId: 'someCredentialId', url: cloneUrl]
    ]
   ])
   sh "git checkout ${branch}"
   return
  } catch (Throwable throwable) {
   //Try next...
  }
 }
 throw new RuntimeException("Could not find any of the ${branches} from ${cloneUrl}")
}

def branches = ['release','develop','master']
doCheckout(cloneUrl, branches)
Run Code Online (Sandbox Code Playgroud)