Created
June 19, 2017 15:14
-
-
Save jseed/ac0218e86c88751942c847b10637bb56 to your computer and use it in GitHub Desktop.
Groovy script for dynamically listing git repository branches as a jenkins build parameter using the extended choice parameter plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Variable bindings: | |
* user - credentials plugin user | |
* url - git repository url (.git) | |
*/ | |
import com.cloudbees.plugins.credentials.CredentialsProvider; | |
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; | |
import jenkins.model.Jenkins | |
def creds = CredentialsProvider.lookupCredentials( | |
StandardUsernamePasswordCredentials.class, | |
Jenkins.instance | |
); | |
def c = creds.findResult { it.username == user ? it : null } | |
def pass = c.password; | |
def repo = "http://" + user + ":" + pass + "@" + url; | |
return ["/bin/bash", "-c", "git ls-remote -h " + repo + " | sed 's/.*refs\\/heads\\/\\(.*\\)/\\1/'"].execute().text.tokenize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you saved me 3 hours!!