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.
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.
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.
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.
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
Change */${BRANCH}
to */$BRANCH
, this works for me.
Branch Specifier (blank for 'any') */$BRANCH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With