Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Multi-Branch job fails for some branches

I have a Jenkins Multi branch job that checks out and builds code from GitLab. Until recently it was working without issue but now some (but not all) branches from the good master fail to build. Master always builds without issue. When I branch master either from the repo in GitLab or via a git checkout -b locally and push back to Gitlab and then allow the multibranch job to pick up the new branch it fails to build it. I get the message from the pipeline plugin SCMBinder class: "Could not determine exact tip revision of [branch]; falling back to nondeterministic checkout". When I do a git status in the workspace on either master or a slave the Head is detached. When I git clone the code locally and checkout the branch everything is fine and the head is properly attached. Additionally, when I create a simple pipeline job in Jenkins with the problem branch it builds ok and inspection of the workspace shows the head attached. I have upgraded Jenkins and the plugins but this has not helped.

The confusing thing is that I have some other branches I created from the same master that builds perfectly fine in the same multibranch pipeline job. Also if I branch a good branch then I get the same issue in the multibranch pipeline.

Can anyone suggest what is going wrong?

like image 615
Alex-Ralph Avatar asked Nov 09 '19 11:11

Alex-Ralph


2 Answers

I also faced similar issue for multi branch Jenkins project.

When I clicked the option "Scan Multi branch pipeline now" in the left side menu, the problem got resolved.

Hope it might help some one.

like image 143
NidhinSPradeep Avatar answered Sep 19 '22 19:09

NidhinSPradeep


I found the answer to this, so answering it here to help others and stop anyone from wasting their time on it.

Essentially this was caused by linux/windows interoperability issues/differences around the use of case in the branch naming which translates into a folder naming issue because windows does not care about case but GIT does.

Simply put, the first branches I previously created for the problem repo I was using a prefix lets call it "Prefix" with an uppercase "P". These branches were pulled into a multi-branch pipe and built ok. Then, I created a branch with the prefix "prefix" with a lower-case "p". This branch failed to build in the multi-branch pipeline.

As we know Windows does not care about case and so does not create a new folder structure in .git for "prefix" as it thinks it has one already called “Prefix”. The appropriate HEAD and commit information is put under the original file structure under “Prefix”. GIT however when it tries to checkout the code cannot find the head/commit information for the branch starting "prefix" as it is looking in .git for the commit/head details under "prefix" and not "Prefix" which does not exist hence results in a detached head.

I am going to start enforcing some syntax rules for branch naming in future so that this does not happen again.

like image 43
Alex-Ralph Avatar answered Sep 21 '22 19:09

Alex-Ralph