@@ -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 ) {
@@ -77,53 +82,100 @@ try {
77
82
ConvertFrom-Json |
78
83
Select-Object - Expand ' native-tools' - ErrorAction SilentlyContinue
79
84
if ($NativeTools ) {
80
- $NativeTools.PSObject.Properties | ForEach-Object {
81
- $ToolName = $_.Name
82
- $ToolVersion = $_.Value
83
- $LocalInstallerArguments = @ { ToolName = " $ToolName " }
84
- $LocalInstallerArguments += @ { InstallPath = " $InstallBin " }
85
- $LocalInstallerArguments += @ { BaseUri = " $BaseUri " }
86
- $LocalInstallerArguments += @ { CommonLibraryDirectory = " $EngCommonBaseDir " }
87
- $LocalInstallerArguments += @ { Version = " $ToolVersion " }
88
-
89
- if ($Verbose ) {
90
- $LocalInstallerArguments += @ { Verbose = $True }
91
- }
92
- if (Get-Variable ' Force' - ErrorAction ' SilentlyContinue' ) {
93
- if ($Force ) {
94
- $LocalInstallerArguments += @ { Force = $True }
95
- }
96
- }
97
- if ($Clean ) {
98
- $LocalInstallerArguments += @ { Clean = $True }
99
- }
100
-
101
- Write-Verbose " Installing $ToolName version $ToolVersion "
102
- Write-Verbose " Executing '$InstallerPath $ ( $LocalInstallerArguments.Keys.ForEach ({" -$_ '$ ( $LocalInstallerArguments .$_ ) '" }) -join ' ' ) '"
103
- & $InstallerPath @LocalInstallerArguments
104
- if ($LASTEXITCODE -Ne " 0" ) {
105
- $errMsg = " $ToolName installation failed"
106
- if ((Get-Variable ' DoNotAbortNativeToolsInstallationOnFailure' - ErrorAction ' SilentlyContinue' ) -and $DoNotAbortNativeToolsInstallationOnFailure ) {
107
- $showNativeToolsWarning = $true
108
- if ((Get-Variable ' DoNotDisplayNativeToolsInstallationWarnings' - ErrorAction ' SilentlyContinue' ) -and $DoNotDisplayNativeToolsInstallationWarnings ) {
109
- $showNativeToolsWarning = $false
85
+ if ($PathPromotion -eq $True ) {
86
+ if ($env: SYSTEM_TEAMPROJECT ) { # check to see if we're in an Azure pipelines build
87
+ $NativeTools.PSObject.Properties | ForEach-Object {
88
+ $ToolName = $_.Name
89
+ $ToolVersion = $_.Value
90
+ $InstalledTools = @ {}
91
+
92
+ if ((Get-Command " $ToolName " - ErrorAction SilentlyContinue) -eq $null ) {
93
+ if ($ToolVersion -eq " latest" ) {
94
+ $ToolVersion = " "
95
+ }
96
+ $ArcadeToolsDirectory = " C:\arcade-tools"
97
+ if (-not (Test-Path $ArcadeToolsDirectory )) {
98
+ Write-Error " Arcade tools directory '$ArcadeToolsDirectory ' was not found; artifacts were not properly installed."
99
+ exit 1
100
+ }
101
+ $ToolDirectory = (Get-ChildItem - Path " $ArcadeToolsDirectory " - Filter " $ToolName -$ToolVersion *" | Sort-Object - Descending)[0 ]
102
+ if ([string ]::IsNullOrWhiteSpace($ToolDirectory )) {
103
+ Write-Error " Unable to find directory for $ToolName $ToolVersion ; please make sure the tool is installed on this image."
104
+ exit 1
110
105
}
111
- if ($showNativeToolsWarning ) {
112
- Write-Warning $errMsg
106
+ $BinPathFile = " $ ( $ToolDirectory.FullName ) \binpath.txt"
107
+ if (-not (Test-Path - Path " $BinPathFile " )) {
108
+ Write-Error " Unable to find binpath.txt in '$ ( $ToolDirectory.FullName ) ' ($ToolName $ToolVersion ); artifact is either installed incorrectly or is not a bootstrappable tool."
109
+ exit 1
113
110
}
114
- $toolInstallationFailure = $true
115
- } else {
116
- # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
117
- Write-Host $errMsg
118
- exit 1
111
+ $BinPath = Get-Content " $BinPathFile "
112
+ $ToolPath = Convert-Path - Path $BinPath
113
+ Write-Host " Adding $ToolName to the path ($ToolPath )..."
114
+ Write-Host " ##vso[task.prependpath]$ToolPath "
115
+ $InstalledTools += @ { $ToolName = $ToolDirectory.FullName }
116
+ }
119
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
+ }
127
+ }
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
+ # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
168
+ Write-Host $errMsg
169
+ exit 1
170
+ }
171
+ }
172
+ }
173
+
174
+ if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
175
+ # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
176
+ Write-Host ' Native tools bootstrap failed'
177
+ exit 1
120
178
}
121
- }
122
-
123
- if ((Get-Variable ' toolInstallationFailure' - ErrorAction ' SilentlyContinue' ) -and $toolInstallationFailure ) {
124
- # We cannot change this to Write-PipelineTelemetryError because of https://github.com/dotnet/arcade/issues/4482
125
- Write-Host ' Native tools bootstrap failed'
126
- exit 1
127
179
}
128
180
}
129
181
else {
@@ -139,7 +191,7 @@ try {
139
191
Write-Host " ##vso[task.prependpath]$ ( Convert-Path - Path $InstallBin ) "
140
192
return $InstallBin
141
193
}
142
- else {
194
+ elseif ( -not ( $PathPromotion )) {
143
195
Write-PipelineTelemetryError - Category ' NativeToolsBootstrap' - Message ' Native tools install directory does not exist, installation failed'
144
196
exit 1
145
197
}
@@ -149,4 +201,4 @@ catch {
149
201
Write-Host $_.ScriptStackTrace
150
202
Write-PipelineTelemetryError - Category ' NativeToolsBootstrap' - Message $_
151
203
ExitWithExitCode 1
152
- }
204
+ }
0 commit comments