-
Notifications
You must be signed in to change notification settings - Fork 654
Description
In GitLab (currently on GitLab Enterprise Edition 14.11.0-pre bf8e20209d4
) and using the latest GitVersion available on DockerHub (5.10.1
), if a branch has a name which contains the word refs
such as:
my-refs-branch
my-test-refs
then detemining the version via gitversion results in the following logs:
INFO [04/28/22 0:45:15:93] Applicable build agent found: 'GitLabCi'.
INFO [04/28/22 0:45:15:98] Working directory: /builds/Daniel-Khodabakhsh/gitversion-bug
INFO [04/28/22 0:45:15:99] Project root is: /builds/Daniel-Khodabakhsh/gitversion-bug/
INFO [04/28/22 0:45:15:99] DotGit directory is: /builds/Daniel-Khodabakhsh/gitversion-bug/.git
INFO [04/28/22 0:45:15:99] Branch from build environment: my-test-refs
INFO [04/28/22 0:45:16:00] Begin: Normalizing git directory for branch 'my-test-refs'
INFO [04/28/22 0:45:16:03] One remote found (origin -> 'https://gitlab-ci-token:*******@gitlab.com/Daniel-Khodabakhsh/gitversion-bug.git').
INFO [04/28/22 0:45:16:04] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
INFO [04/28/22 0:45:16:04] End: Normalizing git directory for branch 'my-test-refs' (Took: 43.80ms)
ERROR [04/28/22 0:45:16:06] An unexpected error occurred:
System.ArgumentException: The canonicalName is not a Canonical name
at GitVersion.ReferenceName.Parse(String canonicalName) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Git\ReferenceName.cs:line 39
at GitVersion.GitPreparer.EnsureLocalBranchExistsForCurrentBranch(IRemote remote, String currentBranch) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 385
at GitVersion.GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitPreparer.cs:line 164
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 [04/28/22 0:45:16:06] Attempting to show the current git graph (please include in issue):
INFO [04/28/22 0:45:16:06] Showing max of 100 commits
INFO [04/28/22 0:45:16:11] * 6a3039b 2 minutes ago (HEAD, origin/my-test-refs, origin/main, refs/pipelines/526468609)
* e06a5d0 4 minutes ago
* 9d9d4b9 6 minutes ago
* dfae72e 7 minutes ago
* 9da59da 8 minutes ago
* 8bec4b1 10 minutes ago
The GitLab CI job is using the docker image of GitLab and is defined below:
stages:
- build
Determine version:
stage: build
image:
name: gittools/gitversion:5.10.1-debian.11-6.0-amd64
entrypoint: ['']
variables:
GIT_DEPTH: 0
script: |
echo "VERSION=$(/tools/dotnet-gitversion /showvariable FullSemVer)" >> build.env
cat build.env
artifacts:
reports:
dotenv: build.env
First saw it on an older version of GitVersion as well (5.6.11-debian.10-x64
).
Expected Behavior
Regardless of the branch name, there should be no error generating the version.
Actual Behavior
Branch names with the word refs
fail.
Possible Fix
Checked the source and it seems like the word refs
in the branch name interferes with the prefix checking in https://github.com/GitTools/GitVersion/blob/support/5.x/src/GitVersion.Core/Git/ReferenceName.cs when checked against these prefixes:
Steps to Reproduce
- Create a GitLab project
- Add the following step to the project's
.gitlab-ci.yml
file:
stages:
- build
Determine version:
stage: build
image:
name: gittools/gitversion:5.10.1-debian.11-6.0-amd64
entrypoint: ['']
variables:
GIT_DEPTH: 0
script: |
echo "VERSION=$(/tools/dotnet-gitversion /showvariable FullSemVer)" >> build.env
cat build.env
artifacts:
reports:
dotenv: build.env
- Create a branch with the word
refs
in it, such asmy-test-refs
. - Run the pipeline.
- Observe that the
Determine version
step of the pipeline fails with the logs mentioned above.
Context
Trying to add automated versioning to my pipeline.
Your Environment
- GitLab:
Enterprise Edition 14.11.0-pre bf8e20209d4
- GitVersion:
5.10.1-debian.11-6.0-amd64
- Example of working run without the word
refs
in the branch name: https://gitlab.com/Daniel-Khodabakhsh/gitversion-bug/-/jobs/2386905935 - Example of failing run with the word
refs
in the branch name: https://gitlab.com/Daniel-Khodabakhsh/gitversion-bug/-/jobs/2386908295