Search code examples
gitjenkinsjenkins-pipeline

How to set branch in Jenkins' Pipeline according to a parameter of the job?


in Jenkins' section Pipeline, I want to set branch of the repository where Jenkinsfile resides to the value of a job's parameter (BRANCH here).Part of the config of the job

But the parameter, although set, is not replaced with its value. Error from the run

This should work, however: when I click on the questioning mark besides "Branches to build", the docs shows the possibility to supply the branch name as a variable. Docs of the option. Could you tell me what should I do better, please?


Solution

  • There was an issue reported similar to this.

    Refer to the following JIRA for more info. https://issues.jenkins.io/browse/JENKINS-42971

    To get yours working you need to do the following:

    1. Select the Prepare Environment to run Prepare an Environment for run
    2. Select the Keep jenkins environment variables
    3. Select the Keep Jenkins build variables
    4. Then in your branch specifier your variable expansion will work. ${BRANCH}