You can use the advanced option select plugin to extract the Git branches of your cloned repository. To do this, add the .git directory path environment variable to the Master-Node property, for example:

Then add the Extensible Choice parameter with the following groovy script (and check the "Use predefined variables" box):
def envVars = jenkins.getNodeProperties()[0].getEnvVars() def NODE_PROJECT_PATH = envVars.get('NODE_PROJECT_PATH') def gettags = "git ls-remote -t --heads origin".execute(null, new File(NODE_PROJECT_PATH)) return gettags.text.readLines() .collect { it.split()[1].replaceAll('\\^\\{\\}', '').replaceAll('refs/\\w+/', '') } .unique() .findAll { !it.startsWith('Branch_') }
This should indicate your branches (I have filtered out all the "Branch_ *" from the list):

Notes: If you do not see anything when checking the script (with the "Run the script now button" button), probably due to the required user / password hint - so first run "git ls-remote -t -heads origin" in the directory .git. To save your credentials on Windows, try running "git config --global credential.helper wincred".
Noam Manos Jun 14 '16 at 11:30 2016-06-14 11:30
source share