Skip to content

Commit e35faa6

Browse files
M168: Azure CLI V2 bugfix (#12899) (#12944)
* Azure CLI V2 bugfix (#12899) * Bug fix * Review comments * Updating task version
1 parent 7dee07a commit e35faa6

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Tasks/AzureCLIV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"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.",
3232
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
3333
"loc.messages.ScriptFailed": "Script failed with error: %s",
34+
"loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",
3435
"loc.messages.ScriptFailedWithExitCode": "Script failed with exit code: %d",
3536
"loc.messages.UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM",
3637
"loc.messages.AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.",

Tasks/AzureCLIV2/azureclitask.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import fs = require("fs");
44
import { Utility } from "./src/Utility";
55
import {ScriptType, ScriptTypeFactory} from "./src/ScriptType";
66

7+
const FAIL_ON_STDERR: string = "FAIL_ON_STDERR";
8+
79
export class azureclitask {
810

911
public static async runMain(): Promise<void> {
@@ -54,10 +56,12 @@ export class azureclitask {
5456
}
5557

5658

57-
if (failOnStdErr) {
59+
if (failOnStdErr && aggregatedErrorLines.length > 0) {
60+
let error = FAIL_ON_STDERR;
5861
aggregatedErrorLines.forEach((err: string) => {
5962
tl.error(err);
6063
});
64+
throw error;
6165
}
6266
}
6367
catch (err) {
@@ -77,7 +81,9 @@ export class azureclitask {
7781
}
7882

7983
//set the task result to either succeeded or failed based on error was thrown or not
80-
if (toolExecutionError) {
84+
if(toolExecutionError === FAIL_ON_STDERR) {
85+
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedStdErr"));
86+
} else if (toolExecutionError) {
8187
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailed", toolExecutionError));
8288
} else if (exitCode != 0){
8389
tl.setResult(tl.TaskResult.Failed, tl.loc("ScriptFailedWithExitCode", exitCode));

Tasks/AzureCLIV2/task.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"messages": {
183183
"ScriptReturnCode": "Script exited with return code: %d",
184184
"ScriptFailed": "Script failed with error: %s",
185+
"ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",
185186
"ScriptFailedWithExitCode": "Script failed with exit code: %d",
186187
"UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM",
187188
"AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.",

Tasks/AzureCLIV2/task.loc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"messages": {
183183
"ScriptReturnCode": "ms-resource:loc.messages.ScriptReturnCode",
184184
"ScriptFailed": "ms-resource:loc.messages.ScriptFailed",
185+
"ScriptFailedStdErr": "ms-resource:loc.messages.ScriptFailedStdErr",
185186
"ScriptFailedWithExitCode": "ms-resource:loc.messages.ScriptFailedWithExitCode",
186187
"UnsupportedEndpointScheme": "ms-resource:loc.messages.UnsupportedEndpointScheme",
187188
"AzureSDKNotFound": "ms-resource:loc.messages.AzureSDKNotFound",

0 commit comments

Comments
 (0)