Jenkins Git Branch not working with Environment Variables

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.

Best Answer

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

Related Topic