Groovy Scripts
How to List Git Branches Dynamically in Jenkins Pipeline Job
I am growing weary of always having to update the list of branches in the choice parameter every time I wish to build a branch that isn’t listed. I like using the Choice Parameter because it cuts down on a.) typo errors; and, b.) having to type something in each time like you’d have to if you used a String Parameter. But, an even better option would be to query GitHub for a list of branches and populate the choices dynamically, further removing the user from being required to type anything…ever!
It appears as though I have two general options: 1.) use a plugin that speaks to GitHub directly, like the Git Parameter List plugin; or, 2.) use a groovy script that gives me full control over what is being queried and what is being displayed.
Resources
Jenkins is the hub of activity for my day-to-day. As is Foreman, Proxmox, GitHub Enterprise, and good ol’ physical machines. We’re not doing anything too complicated with Jenkins, aside from webhook triggers and Groovy libraries.
Here are some helpful resources, to start.