Skip to content

Commit 0c2eccd

Browse files
committed
Update build pipeline to GitVersion 6.6.x and hosted agent
- Migrate from UseGitVersion@5 to gitversion/setup@3 + gitversion/execute@3 - Switch from self-hosted pool to windows-latest - Add full checkout with fetchDepth: 0 and fetchTags - Add tag build workaround for GitVersion detached HEAD issue - Build via solution file instead of individual csproj files
1 parent a3d639b commit 0c2eccd

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

azure-pipelines.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,41 @@ trigger:
88
- refs/tags/v*
99

1010
pool:
11-
name: 'default'
11+
vmImage: windows-latest
12+
1213

1314
variables:
1415
buildConfiguration: 'Release'
1516

1617
steps:
17-
- task: UseGitVersion@5
18+
- checkout: self
19+
clean: true
20+
fetchDepth: 0
21+
fetchTags: true
22+
23+
- task: gitversion/setup@3
1824
inputs:
19-
versionSpec: '5.11.x'
25+
versionSpec: '6.6.x'
26+
27+
# Workaround: Azure DevOps sets BUILD_SOURCEBRANCH to refs/tags/... for tag builds,
28+
# causing GitVersion to fail in detached HEAD mode (see https://github.com/GitTools/GitVersion/issues/4534).
29+
# Setting GIT_BRANCH to the branch containing the tag lets GitVersion resolve the version correctly.
30+
- powershell: |
31+
$sourceBranch = "$(Build.SourceBranch)"
32+
if ($sourceBranch.StartsWith("refs/tags/")) {
33+
$tagCommit = git rev-list -n 1 "$sourceBranch"
34+
$containingBranch = git branch -r --contains $tagCommit |
35+
Where-Object { $_ -match 'origin/(main|master)' } |
36+
Select-Object -First 1
37+
if ($containingBranch) {
38+
$branchName = $containingBranch.Trim().Replace("origin/", "")
39+
Write-Host "Tag build detected - setting GIT_BRANCH to refs/heads/$branchName"
40+
Write-Host "##vso[task.setvariable variable=GIT_BRANCH]refs/heads/$branchName"
41+
}
42+
}
43+
displayName: 'Resolve branch for tag builds'
44+
45+
- task: gitversion/execute@3
2046

2147
- task: DotNetCoreCLI@2
2248
inputs:
@@ -26,7 +52,7 @@ steps:
2652
displayName: Build
2753
inputs:
2854
command: build
29-
projects: '**/*.csproj'
55+
projects: '**/*.sln'
3056
arguments: '--configuration $(buildConfiguration)'
3157

3258
- task: DotNetCoreCLI@2
@@ -52,4 +78,4 @@ steps:
5278
command: 'push'
5379
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
5480
nuGetFeedType: 'internal'
55-
publishVstsFeed: '59a3608a-9bed-4cb4-9467-6efaaa3cbef5/1e425ef4-e3a0-4927-b4c0-2beff753cb88'
81+
publishVstsFeed: '59a3608a-9bed-4cb4-9467-6efaaa3cbef5/1e425ef4-e3a0-4927-b4c0-2beff753cb88'

0 commit comments

Comments
 (0)