Configure Jenkins to build from a user selected Git Branch - DevDummy

Latest

Views | Thoughts | Concepts | Techniques

Wednesday, January 16, 2019

Configure Jenkins to build from a user selected Git Branch




Recently I wanted to set up a Jenkins job in such a way that,
  • It is required to list the current Git branch list in the Job page
  • Allow the user to specify a branch from the list
  • Capture the selection as an input
  • Checkout the code from the selected branch
  • Build the code
However the required parameterized build job is pretty straight forward unless the point 3. After quick research, I noticed that there is no proper pre-defined environment variable to be used here, so we have to look for a user defined variable to capture the user input.

Here is the method I used to achieve this,

List all the branches from Git

In the general section, we have to select the project as "parameterized" then select "Git Parameter"


It will be reflected in the job as follows listing the branches,


Capture the selected branch as an input & build



Here, we have to set the name configured in the "Git Parameter Name" as "Branches to build" in variable notation.

Example : branch_name -> ${branch_name}

...

No comments:

Post a comment