Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins fails to build when I use a parameterised branch: fatal: Couldn't find remote ref refs/heads/${BUILD_BRANCH}

As soon as I attempted to upgrade my Jenkins job to use a parameter for the branch rather than a hard coded value it no longer works.

String parameter

Have tried many other names than BUILD_BRANCH

enter image description here Here I've tried ${env.BUILD_BRANCH}, refs/heads${BUILD_BRANCH} and absolutely none of them work enter image description here When I did this initially I did check lightweight checkout, I removed it after reading many online answers from those having the same problem. Still nothing!. I just added the 'wipe' command to see if that would help but it didn't

error:

 > git rev-list --no-walk 97428a402f3304a21ccc8df435a40468ebf406c1 # timeout=10
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] readTrusted
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/heads/${BUILD_BRANCH}:refs/remotes/origin/${BUILD_BRANCH}" returned status code 128:
stdout: 
stderr: fatal: Couldn't find remote ref refs/heads/${BUILD_BRANCH}
fatal: The remote end hung up unexpectedly

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2429)

Thank you for reading even if you couldn't help

like image 766
King Avatar asked Feb 24 '20 17:02

King


2 Answers

Do you have lightweight checkout selected in the Pipeline SCM section? Unchecking lightweight checkout fixed this issue for me.

like image 152
Stan Gabenov Avatar answered Sep 28 '22 19:09

Stan Gabenov


It seems as if you were mixing configurations (hard to say for sure with just the pieces of images shared).

On one hand, you are defining a parameter (BUILD_BRANCH) to be able to specify which branch should be build.

On another, and assuming that the 2nd image belongs to the Pipeline section of the project configuration, you are trying to use that parameter to limit the branch that should be used to obtain the Jenkinsfile.

That 2nd branch is checked out in a different workspace (different folder) and used only to obtain the Jenkinsfile. Even when you do a full checkout of that, it doesn't mean that you will have the code of that branch available on your workspace.

What you should do, is to use the parameter on your pipeline and feed it to your checkout stage.

like image 43
matus Avatar answered Sep 28 '22 17:09

matus