Skip to content

Commit

Permalink
M168: Azure CLI V2 bugfix (#12899) (#12944)
Browse files Browse the repository at this point in the history
* Azure CLI V2 bugfix (#12899)

* Bug fix

* Review comments

* Updating task version
  • Loading branch information
issacnitinmsft authored May 20, 2020
1 parent 7dee07a commit e35faa6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 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
1 change: 1 addition & 0 deletions Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
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 e35faa6

Please sign in to comment.