-
Notifications
You must be signed in to change notification settings - Fork 654
Error / GitVersion with Jenkins multi-branch pipeline project #1335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For people with similar problems, I've got a workaround. Open the Jenkins multi-branch pipeline project:
|
from memory, Jenkins does a shallow clone so only knows about the branch it is cloning. Have you tried |
Oh interesting! I'll give it a try! Edit: I unchecked Also, the step |
@vader1986 from your edit it seems like you didn't recheck |
Hi, thanks for the reply! I did save after unchecking, but I just rebuild the existing branch. That means it was actually not cloning the repo again, therefore, "cloning behavior" wasn't applied. I guess it would be nice to fetch all after each update of the branch, rather than just for cloning. I'll try to play around a bit more with the Jenkins settings. |
Believe I'm getting a similar error when trying to build a GitHub pull request with Jenkins pipeline. Log file:
I have Jenkins set to checkout tags and not do a shallow clone with the following in my Jenkinsfile:
|
Is it possible to perform a |
In my case I tried that and got:
|
I see. How about |
I ran into this the other day, and I got it to work using |
Just to add to this thread, I'm running into this issue with a multi-branch pipeline script in Jenkins too. |
Here is my solution;
PS: If ssh-agent doesn't work for you, run the following command to add git bash to your path |
Running Jenkins with Multibranch pipeline, similar to above cases.
Found that the issues occurrend when PR and branch builds were using the same build directory, and branch builds would fail after a PR or vice versa. On a hunch, I added:
to start of build scripts, and problem disappeared. Anyone else have a similar result? @theschnarr the first build, you can "Honour refspec on initial clone" - may help in your case. |
Interesting find, @gjonespf. Is it not possible to tell Jenkins to clean the build directory on branch change? In TeamCity you can do that at least. |
Have not fully confirmed this, but so far so good. Oh, and curiously I can pop on the build agent and run GitVersion command line as same user in same dir, and it works fine also. Only difference I can see here is that I'm guessing the build branch is being fed in via env vars when it fails "Branch from build environment", e.g.:
In this case it's failing on an old PR branch that isn't part of the intended build. Tho if I run the command line version with /b "develop", works fine.. |
Running from the command line without the magic environment variables being set by the build server, GitVersion won't run in its "build server" mode and will therefore follow another code path. For Jenkins, it seems like
Can you set that environment variable to trigger the "build server" mode and see whether you can reproduce the problem then, @gjonespf? |
I had this issue and also #1490 after setting |
We are using the Bitbucket Team/Project and hit this problem with 5.0.0 on Jenkins ver. 2.182. What solved the error for us was the comment from @JonCubed here.
I believe I should also note two other things.
|
EDIT: The below doesn't actually work, I had to add the following manual steps to make it work on non-master branches:
I've faced the same issue with Jenkins 2.176.2 in a multi-branch pipeline using GitVersion 5.0.0.0 in the Mainline mode. The fix was to change my usual checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'LocalBranch']],
userRemoteConfigs: scm.userRemoteConfigs
]) Essentially it just adds the
|
This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions. |
@queil, correct – GitVersion needs the build to be performed from an actual branch and that at least |
@asbjornu Well, I think this is a problem with Jenkins, not GitVersion. |
Yes, I agree, but it would be good if GitVersion was a bit more resilient to CI servers acting weird. |
This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions. |
For anyone using JCASC, add something along the lines of
to your "declarative-compatible traits". |
We use jcasc but still face this error from time to time. Very annoying. Our codes:
|
Dropping a comment here because this seems to one of the first few results in Google, hoping other people will be able to find the following solution helpful. My specific use case is that we're building PRs that are being merged to develop, develop has been branched off from master. Only PR builds failed, builds for branches worked as expected. I had read a comment somewhere in this issue that GitVersion requires both the current branch revision as well as a reference to master. Since we're not merging to master, Jenkins doesn't automatically include it, so I had to manually specify it using refspecs. This way it'll always have master, and the branch you're currently trying to build. Adding the Specify ref specs step with the following 2 refspecs has fixed it for me: I also have Advanced clone behaviours with Fetch tags checked, Shallow clone unchecked. |
I have a similar issue using Jenkins and GitHub Enterprise, both internally hosted. I am also unable to modify the git behaviors on individual repos as they are all auto-generated by Jenkins DSL that is triggered by repo activity webhooks. The I copied @queil's code verbatim and still don't see a file created, and i get two errors like this:
The
What do you mean exactly by:
Which change? I am using a pipeline template from a shared library, so it doesn't live in the building repo's Jenkinsfile. The building repo's Jenkinsfile only contains the template instantiator and some params:
Lastly, i tried it with Any help would be greatly appreciated! |
Uh oh!
There was an error while loading. Please reload this page.
This might be related to #912 .
With the default configuration of a multi-branch pipeline project in Jenkins, it's complaining:
An unexpected error occurred: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
If I do
git fetch --all
after checkout, I'm getting:LibGit2Sharp.LibGit2SharpException: ref '...' doesn't match the destination
Interestingly enough, it works, when I
git checkout master
followed bygit checkout ${GIT_BRANCH}
in the Jenkins pipeline fileThe text was updated successfully, but these errors were encountered: