I need to select in a Jenkins job a branch of a GIT repository to work on.
The git-parameter plugin of Jenkins
This standard Jenkins plugin called git-parameter does the job, but it has these limitations (at least in May 2015):
Let's see if we can see other solutions.
Solution based on Groovy scripting
This solution needs a slight modification to the server, supposing you are using gitolite for authorizing the access to your repository.
Modifying your gitolite installation
Following this guide, I have added a new command called branch.
For it to work, I log in to the computer that hosts the gitolite server and edit the
and add this line:
then I create the 'branch' command:
and place this content:
Let's make it executable:
Now let's test it:
It is left as an improvement, to control if the user has access to the repository.
Create the parameter
Now let's configure our Jenkins job to include a parameter.
I use the Extensible choice plugin in order to have a dynamically filled combo box.
I configure to have a source of System Groovy Choice parameter, and enter this small Groovy script:
git highlights the current repo with a star, and places some space at the left for aesthetical purposes.
If the parameter has a name of branch, then in the
Branches to build field you can simply type
This solution is simple, and doesn't have all the limitations of the previous solution.