Hi,
I would like to create a Jenkins job that has a Build Parameters form where the user can enter the name of a Git repo branch and the job will check out that branch of the repo.
I tried using the build parameter name (JJB variable) as the value for "branches" but that doesn't work: I end up with the most recent commit being checked out.
However if I use the build parameter in a shell builder, I can then check out the desired branch.
Example:
---
- job-template:
name: 'xyzzy-{environment}'
project-type: freestyle
parameters:
- string:
name: MY_BRANCH
default: origin/master
description: "Git branch name"
scm:
- git:
url: ... # redacted
branches:
- '{MY_BRANCH}' # this does not work
builders:
- shell: |
git checkout $MY_BRANCH # this does work
Questions:
1. Does putting {MY_BRANCH} on the right hand side of scm.git.branches not work because a build parameter is a different animal than a JJB variable? (Just to verify I understand what's happening.)
2. How is my workaround? Is there a more elegant or JJB-native way to allow users to select the Git branch in the Build Parameters form?
Best,
Aleksey