Skip to content

Commit

Permalink
Azure CLI V2 bugfix (#12899)
Browse files Browse the repository at this point in the history
* Bug fix

* Review comments
  • Loading branch information
issacnitinmsft authored May 18, 2020
1 parent 9d687aa commit 003a2cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
10 changes: 8 additions & 2 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 10
"Patch": 11
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -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.",
Expand Down
3 changes: 2 additions & 1 deletion Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 10
"Patch": 11
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 003a2cd

Please sign in to comment.