@@ -31,6 +31,10 @@ Wait time between retry attempts in seconds
31
31
. PARAMETER GlobalJsonFile
32
32
File path to global.json file
33
33
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
+
34
38
. NOTES
35
39
#>
36
40
[CmdletBinding (PositionalBinding = $false )]
@@ -41,7 +45,8 @@ Param (
41
45
[switch ] $Force = $False ,
42
46
[int ] $DownloadRetries = 5 ,
43
47
[int ] $RetryWaitTimeInSeconds = 30 ,
44
- [string ] $GlobalJsonFile
48
+ [string ] $GlobalJsonFile ,
49
+ [switch ] $PathPromotion
45
50
)
46
51
47
52
if (! $GlobalJsonFile ) {
@@ -76,51 +81,88 @@ try {
76
81
ConvertFrom-Json |
77
82
Select-Object - Expand " native-tools" - ErrorAction SilentlyContinue
78
83
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 }
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
99
+ }
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
104
+ }
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
+ $InstalledTools += @ { $ToolName = $ToolDirectory.FullName }
115
+ }
94
116
}
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
117
+ return $InstalledTools
118
+ } else {
119
+ $NativeTools.PSObject.Properties | ForEach-Object {
120
+ $ToolName = $_.Name
121
+ $ToolVersion = $_.Value
122
+ $LocalInstallerArguments = @ { ToolName = " $ToolName " }
123
+ $LocalInstallerArguments += @ { InstallPath = " $InstallBin " }
124
+ $LocalInstallerArguments += @ { BaseUri = " $BaseUri " }
125
+ $LocalInstallerArguments += @ { CommonLibraryDirectory = " $EngCommonBaseDir " }
126
+ $LocalInstallerArguments += @ { Version = " $ToolVersion " }
127
+
128
+ if ($Verbose ) {
129
+ $LocalInstallerArguments += @ { Verbose = $True }
130
+ }
131
+ if (Get-Variable ' Force' - ErrorAction ' SilentlyContinue' ) {
132
+ if ($Force ) {
133
+ $LocalInstallerArguments += @ { Force = $True }
109
134
}
110
- if ($showNativeToolsWarning ) {
111
- Write-Warning $errMsg
135
+ }
136
+ if ($Clean ) {
137
+ $LocalInstallerArguments += @ { Clean = $True }
138
+ }
139
+
140
+ Write-Verbose " Installing $ToolName version $ToolVersion "
141
+ Write-Verbose " Executing '$InstallerPath $ ( $LocalInstallerArguments.Keys.ForEach ({" -$_ '$ ( $LocalInstallerArguments .$_ ) '" }) -join ' ' ) '"
142
+ & $InstallerPath @LocalInstallerArguments
143
+ if ($LASTEXITCODE -Ne " 0" ) {
144
+ $errMsg = " $ToolName installation failed"
145
+ if ((Get-Variable ' DoNotAbortNativeToolsInstallationOnFailure' - ErrorAction ' SilentlyContinue' ) -and $DoNotAbortNativeToolsInstallationOnFailure ) {
146
+ $showNativeToolsWarning = $true
147
+ if ((Get-Variable ' DoNotDisplayNativeToolsInstallationWarnings' - ErrorAction ' SilentlyContinue' ) -and $DoNotDisplayNativeToolsInstallationWarnings ) {
148
+ $showNativeToolsWarning = $false
149
+ }
150
+ if ($showNativeToolsWarning ) {
151
+ Write-Warning $errMsg
152
+ }
153
+ $toolInstallationFailure = $true
154
+ } else {
155
+ Write-Error $errMsg
156
+ exit 1
112
157
}
113
- $toolInstallationFailure = $true
114
- } else {
115
- Write-Error $errMsg
158
+ }
159
+ }
160
+
161
+ if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
116
162
exit 1
117
163
}
118
164
}
119
165
}
120
-
121
- if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
122
- exit 1
123
- }
124
166
}
125
167
else {
126
168
Write-Host " No native tools defined in global.json"
@@ -134,7 +176,7 @@ try {
134
176
Write-Host " Native tools are available from" (Convert-Path - Path $InstallBin )
135
177
Write-Host " ##vso[task.prependpath]$ ( Convert-Path - Path $InstallBin ) "
136
178
}
137
- else {
179
+ elseif ( -not ( $PathPromotion )) {
138
180
Write-Error " Native tools install directory does not exist, installation failed"
139
181
exit 1
140
182
}
0 commit comments