Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Git Branch not working with Environment Variables

Tags:

jenkins

Folks, There is an environment variable a job is configured with, BRANCH, but when I try configuring git scm with it, i get an error in console

Branch Specifier (blank for 'any') */${BRANCH}

git rev-parse refs/remotes/origin/${BRANCH}^{commit} # timeout=10 git rev-parse refs/remotes/origin/origin/${BRANCH}^{commit} # timeout=10 git rev-parse origin/${BRANCH}^{commit} # timeout=10 ERROR: Couldn't find any revision to build.

I am 100% certain git is fine, branch exists.

like image 338
Cmag Avatar asked Apr 28 '15 20:04

Cmag


People also ask

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

If you want to be able to dynamically give a Git branch to use in a Jenkins build then you'll need to do a couple of things. 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.

Can Jenkins use system environment variables?

Environment variables are global key-value pairs Jenkins can access and inject into a project. Use Jenkins environment variables to avoid having to code the same values for each project. Other benefits of using Jenkins environment variables include improved security.

How does Jenkins pipeline override environment variables?

Overriding Environment VariableAny variable defined in the pipeline environment block can be overridden in the local stage environment. We can check this by overriding the USER_ID to 32, and this variable will override the variable from the pipeline level environment.


2 Answers

So under full checkout , Change */${BRANCH} to */$BRANCH, this should read the environment variable.

Branch Specifier (blank for 'any') */$BRANCH

In Pipelines, make sure you aren't specifying a Lightweight Checkout. As of Jenkins 2.73, Lightweight Checkouts will not read the environment variable, but a full checkout will

Check this issue discussion for more details https://github.com/jenkinsci/ghprb-plugin/issues/564

like image 189
Aarish Ramesh Avatar answered Jan 02 '23 21:01

Aarish Ramesh


Change */${BRANCH} to */$BRANCH, this works for me.

Branch Specifier (blank for 'any') */$BRANCH

like image 31
mainframer Avatar answered Jan 02 '23 20:01

mainframer