イメージ
こんな感じで動的にブランチ一覧をプルダウンで表示させる
やりかた
Extended Choice Parameter Pluginを使います
プラグインをインストールしたら、ビルドパラメータで、Extended Choice Parameterが選択できるので、以下のようにparameter typeにSingle Selectを指定します
Choose Source for Valueに以下のようなGroovy Scriptを指定入力すれば完成です。
listBranches.groovy
# !/usr/bin/env groovy
import hudson.model.*
import jenkins.model.*
def listBranches() {
    // target repo url
    def gitURL = "https://github.com/jenkinsci/jenkins.git"
    // get branches
    def branches = ("git ls-remote -t -h ${gitURL}").execute()
    return branches.text.readLines().collect { it.split()[1].replaceAll('refs/heads/|refs/tags/', '') }.unique().join(",")
}
return listBranches()
プライベートリポジトリの場合は以下のようにJenkinsで管理しているクレデンシャルを取得すればOKです。
listBranches.groovy
# !/usr/bin/env groovy
import hudson.model.*
import jenkins.model.*
def listBranches() {
    // target repo url
    def gitURL = "https://YOUR_PRIVATE_GIT_URL"
    def credentialID = "YOUR_CREDENTIAL_ID"
    // get credential
    def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
        com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class,
        jenkins.model.Jenkins.instance
    )
    def credential = creds.findResult { it.id == credentialID ? it : null}
    // get branches
    gitURL = gitURL.replace("https://", "https://${credential.username}:${credential.password}@")
    def branches = ("git ls-remote -t -h ${gitURL}").execute()
    return branches.text.readLines().collect { it.split()[1].replaceAll('refs/heads/|refs/tags/', '') }.unique().join(",")
}
return listBranches()

