...
1param (
2 [Parameter(Mandatory = $true)]
3 [ValidateNotNullOrEmpty()]
4 [string] $AgentImage
5)
6
7function Throw-InvalidOperatingSystem {
8 throw "Invalid operating system detected. Operating system was: $([System.Runtime.InteropServices.RuntimeInformation]::OSDescription), expected image was: $AgentImage"
9}
10
11if ($IsWindows -and $AgentImage -match "windows|win|MMS2019") {
12 $osName = "Windows"
13} elseif ($IsLinux -and $AgentImage -match "ubuntu") {
14 $osName = "Linux"
15} elseif ($IsMacOs -and $AgentImage -match "macos") {
16 $osName = "macOS"
17} else {
18 Throw-InvalidOperatingSystem
19}
20
21Write-Host "##vso[task.setvariable variable=OSName]$osName"
View as plain text