GitVersion
GitVersion copied to clipboard
[ISSUE]: Azure pipelines always provides -no-branch- as prerelease label although branch is recognized
Prerequisites
- [x] I have written a descriptive issue title
- [x] I have searched issues to ensure it has not already been reported
GitVersion package
GitVersion.Tool
GitVersion version
6.3.0
Operating system
Linux
What are you seeing?
When I am running the Gitversion tool in my Azure pipeline I am always getting -no-branch- as prerelease label/tag on a develop branch. It is somehow related to the fact that Azure pipelines always checks out in detached head mode.
Strangely I can see in the logs that the branch was properly identified:
INFO [25-05-06 16:39:55:38] Branch from build environment: refs/heads/develop
Interestingly the previously used version of the tool (5.8.1) was providing the "develop" branch configuration "label" value when running on the exact same commit. We would like to get this behaviour back.
Any idea what is going wrong in my configuration?
I am pasting my config:
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: ''
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats:
tfs: "^Merged (?:PR (?<PullRequestNumber>\\d+)): Merge '?(?<SourceBranch>[^']+)'? (in)?(to) (?<TargetBranch>.+)"
update-build-number: true
semantic-version-format: Strict
strategies:
- Fallback
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
develop:
mode: ContinuousDelivery
label: develop
increment: Minor
prevent-increment:
of-merged-branch: false
track-merge-target: true
regex: ^(refs/heads/)?develop$
source-branches: []
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-main-branch: false
pre-release-weight: 0
main:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
regex: ^(refs/heads/)?master$|^(refs/heads/)?main$
source-branches:
- develop
- release
- hotfix
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: rc
increment: None
prevent-increment:
of-merged-branch: true
track-merge-target: false
regex: ^(refs/heads/)?releases?[/-](?<BranchName>.+)
source-branches:
- develop
- main
- support
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
prevent-increment:
of-merged-branch: false
track-merge-target: false
regex: ^(refs/heads/)?features?[/-](?<BranchName>.+)
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
is-source-branch-for: []
is-release-branch: false
is-main-branch: false
pre-release-weight: 30000
pull-request:
mode: ManualDeployment
label: PullRequest{Number}
increment: Inherit
prevent-increment:
of-merged-branch: false
track-merge-target: false
regex: ^(refs/)?(pull-requests|pull|pr|pullrequest)[/-](?<Number>\d*)
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
tracks-release-branches: false
is-source-branch-for: []
is-release-branch: false
is-main-branch: false
pre-release-weight: 30000
hotfix:
mode: ManualDeployment
label: beta
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
regex: ^(refs/heads/)?hotfix(es)?[/-](?<BranchName>.+)
source-branches:
- develop
- main
- support
tracks-release-branches: false
is-source-branch-for: []
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
support:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment:
of-merged-branch: true
track-merge-target: false
regex: ^(refs/heads/)?support[/-](?<BranchName>.+)
source-branches:
- main
- pull-request
- feature
- hotfix
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
ignore:
sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment:
of-merged-branch: false
when-branch-merged: false
when-current-commit-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
What is expected?
To get "develop" as "PreReleaseLabel" since the branch name is given via env var BUILD_SOURCEBRANCH.
Steps to Reproduce
#$1 is repo name
#$2 is branch name
#$3 is commit sha1
git init
git remote add origin https://[email protected]/my-org/${1}
git sparse-checkout disable
git config gc.auto 0
git config core.longpaths true
git fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --depth=1 +${3}:refs/remotes/origin/${3}
git fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --depth=1 +${3}
git checkout --progress --force refs/remotes/origin/$3
git submodule sync --recursive
git submodule update --init --force --depth=1 --recursive
log "Unshallowing Git repository"
git fetch --unshallow --no-recurse-submodules
# These env vars are set by Azure pipelines and are used by the gitversion tool. To recognize
# that it is running in a pipeline the TF_BUILD env var is used. The tool then uses the value of BUILD_SOURCEBRANCH to determine
# the branch name.
export TF_BUILD=True
export BUILD_SOURCEBRANCH=refs/heads/$2
export BUILD_BUILDNUMBER=123456
CURR_DIR=$(pwd)
COMMON_CLI_ARGS="/nonormalize /nocache /config "${ROOT_DIR}/GitVersion.yml""
set -x
"${ROOT_DIR}/dotnet-gitversion" "$CURR_DIR" $COMMON_CLI_ARGS /output file /outputfile "${ROOT_DIR}/semver.json" /verbosity Verbose /l "${ROOT_DIR}/semver.log"
set +x
RepositoryFixture Test
No response
Output log or link to your CI build (if appropriate).
I have encountered the same issue. I just fixed it by changing back to the actual branch and not the commit. (i.e. git checkout devfor example) Then I just check that the commit id is the same. Not really elegant, but atleast it works.
Edit. For my usecase, it seems that version 6.3. fixed this issue.
I also advice to add gitversion debug logs into these kind of issues. Maybe someone can then figure it out easier.
Could you provide more repro steps?
@9swampy
Sorry for the long delay of answering. I had to check if I am allowed to post the log file content.
I added more log output to the description in hope that you can help me with debugging. In the log I can see an exception happening and after that I can see the term "(no branch)" showing up.
Just a suggestion: are you able to kill the orphaned branch?
2025-07-09 08:46:41 INFO [25-07-09 8:46:41:36] An orphaned branch 'origin/68d9cf33441760dfb393addf7501efa0b34d54ab' has been detected and will be skipped=True.
2025-07-09 08:46:41 INFO [25-07-09 8:46:41:36] -< End: Fetching the base versions for version calculation... (Took: 61.25ms) >-
2025-07-09 08:46:41 INFO [25-07-09 8:46:41:36] -------------------------------------------------------
2025-07-09 08:46:41 ERROR [25-07-09 8:46:41:37] An unexpected error occurred:
GitVersion.GitVersionException: No base versions determined on the current branch.
at GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 159
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 53
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /_/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 45
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /_/src/GitVersion.App/GitVersionExecutor.cs:line 69
2025-07-09 08:46:41 INFO [25-07-09 8:46:41:37] Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*` to see the git graph. This can help you troubleshoot any issues.
That branch exists only locally because of the way how Azure DevOps pipeline is checking out the branch in detached head state. Check in the description above the row: "git checkout --progress --force refs/remotes/origin/$3" In the remote it does not exist at all.
More and more I feel that even with my "unshallow" this is not gonna work and I will have to simply always make a full clone of the repository.
Will close this work item with this conclusion.
Thanks to everyone who was trying to help.