azure-sdk-for-cpp/eng/common/scripts/Get-BuildSourceDescription.ps1
Azure SDK Bot 744450472d
Sync eng/common directory with azure-sdk-tools for PR 6919 (#4988)
* Add autorest-preview pipeline

* Add emitternpminstall

* Always install

* Use shorter leg name

* Add short circuiting to emitter install

* Use language matrix function

* Don't look for subfolders in the matrix package folders

* Revert unnecessary eng/common changes

* Rewrite GetPullRequestUrl to Get-BuildSourceDescription

* Remove alias from Invoke-LoggedCommand

* Use invoke-expression instead of shelling out

* Add better job splitting

* Replace Folder with Directory

---------

Co-authored-by: Patrick Hallisey <pahallis@microsoft.com>
2023-09-25 12:35:11 -07:00

25 lines
887 B
PowerShell

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"
}