File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,9 +14,34 @@ variables:
1414 buildConfiguration : ' Release'
1515
1616steps :
17- - task : UseGitVersion@5
17+ - checkout : self
18+ clean : true
19+ fetchDepth : 0
20+ fetchTags : true
21+
22+ - task : gitversion/setup@3
1823 inputs :
19- versionSpec : ' 5.11.x'
24+ versionSpec : ' 6.6.x'
25+
26+ # Workaround: Azure DevOps sets BUILD_SOURCEBRANCH to refs/tags/... for tag builds,
27+ # causing GitVersion to fail in detached HEAD mode (see https://github.com/GitTools/GitVersion/issues/4534).
28+ # Setting GIT_BRANCH to the branch containing the tag lets GitVersion resolve the version correctly.
29+ - powershell : |
30+ $sourceBranch = "$(Build.SourceBranch)"
31+ if ($sourceBranch.StartsWith("refs/tags/")) {
32+ $tagCommit = git rev-list -n 1 "$sourceBranch"
33+ $containingBranch = git branch -r --contains $tagCommit |
34+ Where-Object { $_ -match 'origin/(main|master)' } |
35+ Select-Object -First 1
36+ if ($containingBranch) {
37+ $branchName = $containingBranch.Trim().Replace("origin/", "")
38+ Write-Host "Tag build detected - setting GIT_BRANCH to refs/heads/$branchName"
39+ Write-Host "##vso[task.setvariable variable=GIT_BRANCH]refs/heads/$branchName"
40+ }
41+ }
42+ displayName : ' Resolve branch for tag builds'
43+
44+ - task : gitversion/execute@3
2045
2146- task : DotNetCoreCLI@2
2247 inputs :
You can’t perform that action at this time.
0 commit comments