From 003a2cd9b84e76e1e8eb47508773a8c494ceaabf Mon Sep 17 00:00:00 2001 From: Nitin Issac Joy Date: Mon, 18 May 2020 14:42:15 +0530 Subject: [PATCH] Azure CLI V2 bugfix (#12899) * Bug fix * Review comments --- .../Strings/resources.resjson/en-US/resources.resjson | 1 + Tasks/AzureCLIV2/azureclitask.ts | 10 ++++++++-- Tasks/AzureCLIV2/task.json | 3 ++- Tasks/AzureCLIV2/task.loc.json | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Tasks/AzureCLIV2/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureCLIV2/Strings/resources.resjson/en-US/resources.resjson index d5379bee6b02..d1429cf68e70 100644 --- a/Tasks/AzureCLIV2/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureCLIV2/Strings/resources.resjson/en-US/resources.resjson @@ -31,6 +31,7 @@ "loc.input.help.powerShellIgnoreLASTEXITCODE": "If this is false, the line `if ((Test-Path -LiteralPath variable:\\LASTEXITCODE)) { exit $LASTEXITCODE }` is appended to the end of your script. This will cause the last exit code from an external command to be propagated as the exit code of powershell. Otherwise the line is not appended to the end of your script.", "loc.messages.ScriptReturnCode": "Script exited with return code: %d", "loc.messages.ScriptFailed": "Script failed with error: %s", + "loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.", "loc.messages.ScriptFailedWithExitCode": "Script failed with exit code: %d", "loc.messages.UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM", "loc.messages.AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.", diff --git a/Tasks/AzureCLIV2/azureclitask.ts b/Tasks/AzureCLIV2/azureclitask.ts index 171c2e1a23ee..9d9ed4acc38f 100644 --- a/Tasks/AzureCLIV2/azureclitask.ts +++ b/Tasks/AzureCLIV2/azureclitask.ts @@ -4,6 +4,8 @@ import fs = require("fs"); import { Utility } from "./src/Utility"; import {ScriptType, ScriptTypeFactory} from "./src/ScriptType"; +const FAIL_ON_STDERR: string = "FAIL_ON_STDERR"; + export class azureclitask { public static async runMain(): Promise { @@ -54,10 +56,12 @@ export class azureclitask { } - if (failOnStdErr) { + if (failOnStdErr && aggregatedErrorLines.length > 0) { + let error = FAIL_ON_STDERR; aggregatedErrorLines.forEach((err: string) => { tl.error(err); }); + throw error; } } catch (err) { @@ -77,7 +81,9 @@ export class azureclitask { } //set the task result to either succeeded or failed based on error was thrown or not - if (toolExecutionError) { + if(toolExecutionError === FAIL_ON_STDERR) { + tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedStdErr")); + } else if (toolExecutionError) { tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailed", toolExecutionError)); } else if (exitCode != 0){ tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedWithExitCode", exitCode)); diff --git a/Tasks/AzureCLIV2/task.json b/Tasks/AzureCLIV2/task.json index 86f86fbcfebe..7b0cf93b0bdd 100644 --- a/Tasks/AzureCLIV2/task.json +++ b/Tasks/AzureCLIV2/task.json @@ -20,7 +20,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 10 + "Patch": 11 }, "minimumAgentVersion": "2.0.0", "instanceNameFormat": "Azure CLI $(scriptPath)", @@ -182,6 +182,7 @@ "messages": { "ScriptReturnCode": "Script exited with return code: %d", "ScriptFailed": "Script failed with error: %s", + "ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.", "ScriptFailedWithExitCode": "Script failed with exit code: %d", "UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM", "AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.", diff --git a/Tasks/AzureCLIV2/task.loc.json b/Tasks/AzureCLIV2/task.loc.json index 18332f4c8301..fbd8db1915af 100644 --- a/Tasks/AzureCLIV2/task.loc.json +++ b/Tasks/AzureCLIV2/task.loc.json @@ -20,7 +20,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 10 + "Patch": 11 }, "minimumAgentVersion": "2.0.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", @@ -182,6 +182,7 @@ "messages": { "ScriptReturnCode": "ms-resource:loc.messages.ScriptReturnCode", "ScriptFailed": "ms-resource:loc.messages.ScriptFailed", + "ScriptFailedStdErr": "ms-resource:loc.messages.ScriptFailedStdErr", "ScriptFailedWithExitCode": "ms-resource:loc.messages.ScriptFailedWithExitCode", "UnsupportedEndpointScheme": "ms-resource:loc.messages.UnsupportedEndpointScheme", "AzureSDKNotFound": "ms-resource:loc.messages.AzureSDKNotFound",