2013-10-22 72 views
5

在我的項目中我有一個GitFlow樣式倉庫。Jenkins Git分支選擇與回退

我怎樣才能讓詹金斯做到以下幾點:(XXXX =釋放否)

  1. 構建發佈-XXXX分支
  2. 如果釋放分支不存在建立主分支。

我明白我可以使用git-chooser-alternative插件把分支機構的優先順序,但我不知道如何選擇包含單詞釋放 -

回答

0

您可以使用管道這個分支。

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)