Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Pipeline using a Branch Parameter

I seem unable to create a Jenkins Pipeline job that builds a specific branch, where that branch is a build parameter.

Here's some configuration screenshots:

param config (i've tried with a Git Parameter and a String Parameter, same outcome)

branch config (I've tried $BRANCH_NAME_PARAM, ${BRANCH_NAME_PARAM} and ${env.BRANCH_NAME_PARAM}, same outcome for all variations)

enter image description here

And the build log:

hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/${BRANCH_NAME_PARAM}:refs/remotes/origin/${BRANCH_NAME_PARAM} --prune" returned status code 128: stdout:  stderr: fatal: Couldn't find remote ref refs/heads/${BRANCH_NAME_PARAM}      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1970) 

I'm obviously doing something wrong - any ideas on what?

like image 448
Chris White Avatar asked Nov 30 '17 04:11

Chris White


People also ask

How do I pass a git branch as parameter in Jenkins?

Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.

How do you run a build with parameters in Jenkins?

To execute the Jenkins job from Jenkins web interface first go to respective project workspace and then click on “Build with Parameters” option from left panel. After that, you will be asked to choose/set parameter value (In my project I have set BROWSER parameter.)

How do you parameterize a branch name in Jenkins pipeline?

Then, in your Pipeline configuration, under Branches to build, add your parameter name inside the Branch Specifier box, surrounded by ${} . Jenkins will expand your variable when the job runs. Now you can specify the branch name as a parameter when you next run your Job.


1 Answers

https://issues.jenkins-ci.org/plugins/servlet/mobile#issue/JENKINS-28447

Appears that its something to do with a lightweight checkout. if i deselect this option in my config, my parameter variables are resolved

like image 65
Chris White Avatar answered Sep 24 '22 10:09

Chris White