GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

[Bug] Unable to run with jenkins multi-branch pipeline.

Open madelaney opened this issue 3 years ago • 7 comments

Describe the bug When trying to use this tool with Jenkins (2.361.1), when I try to generate the next version. I get an error about LibGit2Sharp.LibGit2SharpException: ref '...' doesn't match the destination.

I've reviewed #1335 but none of the suggested work arounds worked for me.

Actual Behavior

Given the config.xml stanza. When the build runs, I get the nasty exception of:

INFO [09/08/22 15:59:18:23] Begin: Normalizing git directory for branch 'feature/jenkins/branch-nameA'
  INFO [09/08/22 15:59:18:25] One remote found (origin -> 'https://bitbucket.org/....').
  INFO [09/08/22 15:59:18:25] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [09/08/22 15:59:18:26] Updating local branch feature/jenkins/branch-nameA to match ref feature/jenkins/branch-nameA
  INFO [09/08/22 15:59:18:29] Creating local branch from remote tracking 'refs/remotes/origin/bugfix/NNNN-2617/branch-nameB'.
  INFO [09/08/22 15:59:18:30] End: Normalizing git directory for branch 'feature/jenkins/branch-nameA' (Took: 68.83ms)
  ERROR [09/08/22 15:59:18:31] An unexpected error occurred:
LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/bugfix/NNNN-2617/branch-nameB' doesn't match the destination
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 154
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 172
   at LibGit2Sharp.Core.Proxy.git_refspec_rtransform(IntPtr refSpecPtr, String name) in /_/LibGit2Sharp/Core/Proxy.cs:line 2088
   at LibGit2Sharp.Remote.FetchSpecTransformToSource(String reference) in /_/LibGit2Sharp/Remote.cs:line 138
   at LibGit2Sharp.BranchUpdater.GetUpstreamInformation(String canonicalName, String& remoteName, String& mergeBranchName) in /_/LibGit2Sharp/BranchUpdater.cs:line 188
   at LibGit2Sharp.BranchUpdater.SetUpstream(String upstreamBranchName) in /_/LibGit2Sharp/BranchUpdater.cs:line 116
   at LibGit2Sharp.BranchUpdater.set_TrackedBranch(String value) in /_/LibGit2Sharp/BranchUpdater.cs:line 53
   at GitVersion.BranchCollection.<>c__DisplayClass7_0.<UpdateTrackedBranch>g__Updater|0(BranchUpdater branchUpdater) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\BranchCollection.cs:line 43
   at LibGit2Sharp.BranchCollection.Update(Branch branch, Action`1[] actions) in /_/LibGit2Sharp/BranchCollection.cs:line 290
   at GitVersion.BranchCollection.UpdateTrackedBranch(IBranch branch, String remoteTrackingReferenceName) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\BranchCollection.cs:line 45
   at GitVersion.GitPreparer.CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(String remoteName) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 352
   at GitVersion.GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 165
   at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 134
   at GitVersion.GitPreparer.PrepareInternal(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 69
   at GitVersion.GitPreparer.Prepare() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 48
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 43
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [09/08/22 15:59:18:31] Attempting to show the current git graph (please include in issue): 
  INFO [09/08/22 15:59:18:31] Showing max of 100 commits
  INFO [09/08/22 15:59:18:35] * 68885a00 80 minutes ago  (HEAD -> feature/jenkins/branch-nameA origin/feature/jenkins/branch-nameA)

Steps to Reproduce

Build using Bitbucket Branch plugin for Jenkins

Context

This caused the .property file to not get created.

Your Environment

  • Jenkins UI (2.361.1)
  • Agent:
    • Ubuntu 20.04LTS
    • dotnet sdk 6.0
    • GitVersion 5.10.3

madelaney avatar Sep 08 '22 20:09 madelaney

Is feature/jenkins/branch-nameA an actual branch name or is it just there as an example?

asbjornu avatar Sep 08 '22 21:09 asbjornu

It's there as an example name. However, the branch is in the feature/jenkins/... directory so I wanted to show the depth of the current branch; in case it matters.

madelaney avatar Sep 09 '22 20:09 madelaney

I was just wondering whether the branch names had upper and lowercase letters in them, because that is a known source of problems for mixed Windows/Linux environments.

asbjornu avatar Sep 09 '22 21:09 asbjornu

We're running this on Linux (Ubuntu 20.04LTS) and the branch names are a mix of upper and loser case values. Some examples would be:

  • feature/NAN-2222/did-you-get-that-thing-i-sent
  • bugfix/NAN-1111/npm-audit-fixes
  • hotfix/0.13/NAN-999/run-it-with-link-to-run-details
  • chore/fix-a-typo
  • feature/jenkins/use-jenkins-for-build

From our developer perspective, we do have a mix of Windows & Mac OS; our build machines are migrating from Windows to Linux.

madelaney avatar Sep 12 '22 11:09 madelaney

Then that may definitely be the cause of this bug, as feature/NAN-2222 would be considered a different branch (and physical directory on disk) to feature/nan-2222 and feature/NaN-2222 on most Linux filesystems, while on Windows and macOS, they will be considered equal (on creation).

I would recommend that you keep all your branch names all-lowercase to avoid these x-plat file system issues.

asbjornu avatar Sep 12 '22 13:09 asbjornu

I think that's fair, and I'm a snake_case in lower case fan, but being what it is this is an existing repo in which branch names are at the behest of the developer.

madelaney avatar Sep 12 '22 14:09 madelaney

I understand, but there's nothing we can do in GitVersion to avoid this. You will have to build some checks before running GitVersion that does some case-insensitive checks on branches before they are checked out and/or before running GitVersion to mitigate this.

asbjornu avatar Sep 12 '22 15:09 asbjornu

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.

github-actions[bot] avatar Mar 04 '23 09:03 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Thank you for your contributions

github-actions[bot] avatar Apr 03 '23 11:04 github-actions[bot]