File: Get-BuildSourceDescription.ps1

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (24 lines) | stat: -rw-r--r-- 887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
param(
  [string]$Variable,
  [switch]$IsOutput
)

$repoUrl = $env:BUILD_REPOSITORY_URI
$sourceBranch = $env:BUILD_SOURCEBRANCH

$description = "[$sourceBranch]($repoUrl/tree/$sourceBranch)" 
if ($sourceBranch -match "^refs/heads/(.+)$") {
    $description = "Branch: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
} elseif ($sourceBranch -match "^refs/tags/(.+)$") {
    $description = "Tag: [$($Matches[1])]($repoUrl/tree/$sourceBranch)"
} elseif ($sourceBranch -match "^refs/pull/(\d+)/(head|merge)$") {
    $description = "Pull request: $repoUrl/pull/$($Matches[1])"
}

if ($IsOutput) {
  Write-Host "Setting output variable '$Variable' to '$description'"
  Write-Host "##vso[task.setvariable variable=$Variable;isoutput=true]$description"
} else {
  Write-Host "Setting variable '$Variable' to '$description'"
  Write-Host "##vso[task.setvariable variable=$Variable]$description"
}