Skip to content

Commit 2ad3b09

Browse files
authored
Add optional HostException handler in Invoke-Tool (#822)
* Add HostException handler * Update error handling for HostException * Update vmImage for windows part * Update way of processing HostException * Change image to win 2019 * Fix naming
1 parent 82f3744 commit 2ad3b09

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
#################################################
1010
displayName: windows
1111
pool:
12-
vmImage: vs2017-win2016
12+
vmImage: windows-2019
1313

1414
steps:
1515
################################################################################

powershell/VstsTaskSdk/ToolFunctions.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ function Invoke-Tool { # TODO: RENAME TO INVOKE-PROCESS?
8686
[string]$Arguments,
8787
[string]$WorkingDirectory,
8888
[System.Text.Encoding]$Encoding,
89-
[switch]$RequireExitCodeZero)
89+
[switch]$RequireExitCodeZero,
90+
[bool]$IgnoreHostException)
9091

9192
Trace-EnteringInvocation $MyInvocation
9293
$isPushed = $false
@@ -104,7 +105,15 @@ function Invoke-Tool { # TODO: RENAME TO INVOKE-PROCESS?
104105

105106
$FileName = $FileName.Replace('"', '').Replace("'", "''")
106107
Write-Host "##[command]""$FileName"" $Arguments"
107-
Invoke-Expression "& '$FileName' --% $Arguments"
108+
try {
109+
Invoke-Expression "& '$FileName' --% $Arguments"
110+
} catch [System.Management.Automation.Host.HostException] {
111+
if ($IgnoreHostException -eq $False) {
112+
throw
113+
}
114+
115+
Write-Host "##[warning]Host Exception was thrown by Invoke-Expression, suppress it due IgnoreHostException setting"
116+
}
108117
Write-Verbose "Exit code: $LASTEXITCODE"
109118
if ($RequireExitCodeZero -and $LASTEXITCODE -ne 0) {
110119
Write-Error (Get-LocString -Key PSLIB_Process0ExitedWithCode1 -ArgumentList ([System.IO.Path]::GetFileName($FileName)), $LASTEXITCODE)

powershell/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

powershell/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vsts-task-sdk",
3-
"version": "0.12.0",
3+
"version": "0.13.0",
44
"description": "VSTS Task SDK",
55
"scripts": {
66
"build": "node make.js build",

0 commit comments

Comments
 (0)