Jenkins Multi-Branch job fails for some branches
Asked Answered
D

4

13

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?

Dniester answered 9/11, 2019 at 11:8 Comment(0)
C
26

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.

Chimera answered 18/5, 2020 at 5:14 Comment(0)
D
5

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.

Dniester answered 11/11, 2019 at 14:31 Comment(1)
Thanks for posting this followup. This was 100% exactly my problem and solutionPommel
S
2

I got this problem apparently because of a Jenkins upgrade. I had to (re)create the "Branch Sources" part of the configuration to fix it.

Sindee answered 12/3, 2021 at 12:56 Comment(0)
K
0

I had the same issue exactly , but with Bitbucket . For me the issue happened due to a dev/ or Dev/ Prefix being used, While the only prefixes defines on the Bitbucket side were : bugfix/ feature/ hotfix/ release/

Tested the same branch with feature/ instead of dev/ worked perfectly , Also changing the prefix from feature/ to dev/ in bitbucket worked , but the issue there is that you cant add additional prefixed , only change one of the four already there , so i just ended up enforcing a policy to prevent people from using dev/ or any other abnormal prefixes in their branch names.

Karachi answered 17/1, 2023 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.