File: set-default-branch.yml

package info (click to toggle)
python-azure 20251014%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 766,472 kB
  • sloc: python: 6,314,744; ansic: 804; javascript: 287; makefile: 198; sh: 198; xml: 109
file content (18 lines) | stat: -rw-r--r-- 823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
parameters:
  WorkingDirectory: '$(System.DefaultWorkingDirectory)'
  RemoteRepo: 'origin'
  DefaultBranchVariableName: DefaultBranch
  Condition: 'succeeded()'
steps:
- pwsh: |
    $setDefaultBranch = (git remote show ${{ parameters.RemoteRepo }} | Out-String) -replace "(?ms).*HEAD branch: (\w+).*", '$1'
    if ($LASTEXITCODE -ne 0) {
      Write-Host "Not able to fetch the default branch from git command. Set to main."
      $setDefaultBranch = 'main'
    }
    Write-Host "Setting ${{ parameters.DefaultBranchVariableName }}=$setDefaultBranch"
    Write-Host "##vso[task.setvariable variable=${{ parameters.DefaultBranchVariableName }}]$setDefaultBranch"
  displayName: "Setup Default Branch"
  workingDirectory: ${{ parameters.workingDirectory }}
  condition: ${{ parameters.Condition }}
  ignoreLASTEXITCODE: true