LoginSignup
1
3

More than 5 years have passed since last update.

jenkinsでブランチを選択してチェックアウト

Posted at

git cloneした後、リモートブランチ一覧から選択してチェックアウトするようにした際のjenkinsファイルの一部を抜粋しました。

stage 'Git clone'
    git credentialsId: "${env.GIT_ID}", url: "${env.GIT_SERVICE_URL}"

stage 'CheckOut Branch'
    def branchlist = (sh(script: 'git branch -r', returnStdout: true)).replaceAll(/(.*?)origin\//,"")
    def selectedbranch = input id: 'selectbranch',
          message: 'selectbranch',
          ok: 'Okay',
          parameters: [
          [ 
            $class: 'ChoiceParameterDefinition', choices: branchlist, 
            name: 'Take your pick',
            description: 'A select box option'
          ]
    ]  
    sh(script: "git checkout ${selectedbranch}", returnStdout: true)
  • env.GIT_IDはjenkis側でもっているGIT-ID
  • env.GIT_SERVICE_URLは環境変数で設定しているGITのURL
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3