Reputation: 1893
I want to know if it's possible to list from a dropdown the GIT branches that are inside my repo dynamically on Jenkins, what I mean by this is if I currently have 3 branches (master/stage/dev) I want them to show on the dropdown when executing the job, but if tomorrow I add a new one, I want that new one to show without me to go and add the new option.
Thanks in advance!
Upvotes: 2
Views: 3162
Reputation: 1303
There is a way to do it with a Active Choices Reactive Parameter
Jenkins Plugin.
Step 1: You need to first install a plugin for Jenkins.
Manage Jenkins
Manage Plugins
Available
tab search for Active Choices Plug-in
Step 2: After Plugin is installed, add a parameter to your pipeline
Go to your pipeline
--> Configure --> General
Find Setting This project is parameterised
and click it if not active yet
Click Add Parameter
and choose Active choices reactive parameter
Give the parameter a name (e.g. BRANCH)
Choose Groovy Script
and add the following script as it is (only changing the link to your repo)
def gettags = ("git ls-remote -t -h [email protected]:YOUR_REPO.git").execute() return gettags.text.readLines().collect { it.split()1.replaceAll('refs/heads/', '').replaceAll('refs/tags/','').replaceAll("\^\{\}", '') }
You're done!
Upvotes: 0
Reputation: 2636
did you check - https://wiki.jenkins.io/display/JENKINS/Git+Parameter+Plugin ?
you just need to add a git parameter , and a new dropdown will appear.
Upvotes: 2