@@ -31,6 +31,10 @@ Wait time between retry attempts in seconds
3131. PARAMETER GlobalJsonFile
3232File path to global.json file
3333
34+ . PARAMETER PathPromotion
35+ Optional switch to enable either promote native tools specified in the global.json to the path (in Azure Pipelines)
36+ or break the build if a native tool is not found on the path (on a local dev machine)
37+
3438. NOTES
3539#>
3640[CmdletBinding (PositionalBinding = $false )]
@@ -41,7 +45,8 @@ Param (
4145 [switch ] $Force = $False ,
4246 [int ] $DownloadRetries = 5 ,
4347 [int ] $RetryWaitTimeInSeconds = 30 ,
44- [string ] $GlobalJsonFile
48+ [string ] $GlobalJsonFile ,
49+ [switch ] $PathPromotion
4550)
4651
4752if (! $GlobalJsonFile ) {
@@ -76,53 +81,100 @@ try {
7681 ConvertFrom-Json |
7782 Select-Object - Expand " native-tools" - ErrorAction SilentlyContinue
7883 if ($NativeTools ) {
79- $NativeTools.PSObject.Properties | ForEach-Object {
80- $ToolName = $_.Name
81- $ToolVersion = $_.Value
82- $LocalInstallerArguments = @ { ToolName = " $ToolName " }
83- $LocalInstallerArguments += @ { InstallPath = " $InstallBin " }
84- $LocalInstallerArguments += @ { BaseUri = " $BaseUri " }
85- $LocalInstallerArguments += @ { CommonLibraryDirectory = " $EngCommonBaseDir " }
86- $LocalInstallerArguments += @ { Version = " $ToolVersion " }
87-
88- if ($Verbose ) {
89- $LocalInstallerArguments += @ { Verbose = $True }
90- }
91- if (Get-Variable ' Force' - ErrorAction ' SilentlyContinue' ) {
92- if ($Force ) {
93- $LocalInstallerArguments += @ { Force = $True }
94- }
95- }
96- if ($Clean ) {
97- $LocalInstallerArguments += @ { Clean = $True }
98- }
99-
100- Write-Verbose " Installing $ToolName version $ToolVersion "
101- Write-Verbose " Executing '$InstallerPath $ ( $LocalInstallerArguments.Keys.ForEach ({" -$_ '$ ( $LocalInstallerArguments .$_ ) '" }) -join ' ' ) '"
102- & $InstallerPath @LocalInstallerArguments
103- if ($LASTEXITCODE -Ne " 0" ) {
104- $errMsg = " $ToolName installation failed"
105- if ((Get-Variable ' DoNotAbortNativeToolsInstallationOnFailure' - ErrorAction ' SilentlyContinue' ) -and $DoNotAbortNativeToolsInstallationOnFailure ) {
106- $showNativeToolsWarning = $true
107- if ((Get-Variable ' DoNotDisplayNativeToolsInstallationWarnings' - ErrorAction ' SilentlyContinue' ) -and $DoNotDisplayNativeToolsInstallationWarnings ) {
108- $showNativeToolsWarning = $false
84+ if ($PathPromotion -eq $True ) {
85+ if ($env: SYSTEM_TEAMPROJECT ) { # check to see if we're in an Azure pipelines build
86+ $NativeTools.PSObject.Properties | ForEach-Object {
87+ $ToolName = $_.Name
88+ $ToolVersion = $_.Value
89+ $InstalledTools = @ {}
90+
91+ if ((Get-Command " $ToolName " - ErrorAction SilentlyContinue) -eq $null ) {
92+ if ($ToolVersion -eq " latest" ) {
93+ $ToolVersion = " "
94+ }
95+ $ArcadeToolsDirectory = " C:\arcade-tools"
96+ if (-not (Test-Path $ArcadeToolsDirectory )) {
97+ Write-Error " Arcade tools directory '$ArcadeToolsDirectory ' was not found; artifacts were not properly installed."
98+ exit 1
10999 }
110- if ($showNativeToolsWarning ) {
111- Write-Warning $errMsg
100+ $ToolDirectory = (Get-ChildItem - Path " $ArcadeToolsDirectory " - Filter " $ToolName -$ToolVersion *" | Sort-Object - Descending)[0 ]
101+ if ([string ]::IsNullOrWhiteSpace($ToolDirectory )) {
102+ Write-Error " Unable to find directory for $ToolName $ToolVersion ; please make sure the tool is installed on this image."
103+ exit 1
112104 }
113- $toolInstallationFailure = $true
114- } else {
115- Write-Error $errMsg
116- exit 1
105+ $BinPathFile = " $ ( $ToolDirectory.FullName ) \binpath.txt"
106+ if (-not (Test-Path - Path " $BinPathFile " )) {
107+ Write-Error " Unable to find binpath.txt in '$ ( $ToolDirectory.FullName ) ' ($ToolName $ToolVersion ); artifact is either installed incorrectly or is not a bootstrappable tool."
108+ exit 1
109+ }
110+ $BinPath = Get-Content " $BinPathFile "
111+ $ToolPath = Convert-Path - Path $BinPath
112+ Write-Host " Adding $ToolName to the path ($ToolPath )..."
113+ Write-Host " ##vso[task.prependpath]$ToolPath "
114+ $env: PATH = " $ToolPath ;$env: PATH "
115+ $InstalledTools += @ { $ToolName = $ToolDirectory.FullName }
116+ }
117+ }
118+ return $InstalledTools
119+ } else {
120+ $NativeTools.PSObject.Properties | ForEach-Object {
121+ $ToolName = $_.Name
122+ $ToolVersion = $_.Value
123+
124+ if ((Get-Command " $ToolName " - ErrorAction SilentlyContinue) -eq $null ) {
125+ Write-PipelineTelemetryError - Category ' NativeToolsBootstrap' - Message " $ToolName not found on path. Please install $ToolName $ToolVersion before proceeding."
126+ }
117127 }
128+ exit 0
129+ }
130+ } else {
131+ $NativeTools.PSObject.Properties | ForEach-Object {
132+ $ToolName = $_.Name
133+ $ToolVersion = $_.Value
134+ $LocalInstallerArguments = @ { ToolName = " $ToolName " }
135+ $LocalInstallerArguments += @ { InstallPath = " $InstallBin " }
136+ $LocalInstallerArguments += @ { BaseUri = " $BaseUri " }
137+ $LocalInstallerArguments += @ { CommonLibraryDirectory = " $EngCommonBaseDir " }
138+ $LocalInstallerArguments += @ { Version = " $ToolVersion " }
139+
140+ if ($Verbose ) {
141+ $LocalInstallerArguments += @ { Verbose = $True }
142+ }
143+ if (Get-Variable ' Force' - ErrorAction ' SilentlyContinue' ) {
144+ if ($Force ) {
145+ $LocalInstallerArguments += @ { Force = $True }
146+ }
147+ }
148+ if ($Clean ) {
149+ $LocalInstallerArguments += @ { Clean = $True }
150+ }
151+
152+ Write-Verbose " Installing $ToolName version $ToolVersion "
153+ Write-Verbose " Executing '$InstallerPath $ ( $LocalInstallerArguments.Keys.ForEach ({" -$_ '$ ( $LocalInstallerArguments .$_ ) '" }) -join ' ' ) '"
154+ & $InstallerPath @LocalInstallerArguments
155+ if ($LASTEXITCODE -Ne " 0" ) {
156+ $errMsg = " $ToolName installation failed"
157+ if ((Get-Variable ' DoNotAbortNativeToolsInstallationOnFailure' - ErrorAction ' SilentlyContinue' ) -and $DoNotAbortNativeToolsInstallationOnFailure ) {
158+ $showNativeToolsWarning = $true
159+ if ((Get-Variable ' DoNotDisplayNativeToolsInstallationWarnings' - ErrorAction ' SilentlyContinue' ) -and $DoNotDisplayNativeToolsInstallationWarnings ) {
160+ $showNativeToolsWarning = $false
161+ }
162+ if ($showNativeToolsWarning ) {
163+ Write-Warning $errMsg
164+ }
165+ $toolInstallationFailure = $true
166+ } else {
167+ Write-Error $errMsg
168+ exit 1
169+ }
170+ }
171+ }
172+
173+ if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
174+ exit 1
118175 }
119176 }
120-
121- if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
122- exit 1
123- }
124- }
125- else {
177+ } else {
126178 Write-Host " No native tools defined in global.json"
127179 exit 0
128180 }
@@ -134,7 +186,7 @@ try {
134186 Write-Host " Native tools are available from" (Convert-Path - Path $InstallBin )
135187 Write-Host " ##vso[task.prependpath]$ ( Convert-Path - Path $InstallBin ) "
136188 }
137- else {
189+ elseif ( -not ( $PathPromotion )) {
138190 Write-Error " Native tools install directory does not exist, installation failed"
139191 exit 1
140192 }
0 commit comments