...
1parameters:
2 WorkingDirectory: '$(System.DefaultWorkingDirectory)'
3 RemoteRepo: 'origin'
4 DefaultBranchVariableName: DefaultBranch
5steps:
6- pwsh: |
7 $setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1'
8 if ($LASTEXITCODE -ne 0) {
9 Write-Host "Not able to fetch the default branch from git command. Set to main."
10 $setDefaultBranch = 'main'
11 }
12 Write-Host "Setting ${{ parameters.DefaultBranchVariableName }}=$setDefaultBranch"
13 Write-Host "##vso[task.setvariable variable=${{ parameters.DefaultBranchVariableName }}]$setDefaultBranch"
14 displayName: "Setup Default Branch"
15 workingDirectory: ${{ parameters.workingDirectory }}
16 ignoreLASTEXITCODE: true
View as plain text