Skip to content

Commit 5278dc6

Browse files
piotr-gbyliczekMaxim ZaytsevVladyslav HorbachovLeftTwixWand
authored
No output toggle for az login within the AzureCLIV2 task (#16701)
* Update task.json Added `visibleAzLogin` boolean to enable hiding az login output (which can be verbose at times with all subscriptions) * Update azureclitask.ts Added option to both login schemes to suppress the output. * Update azureclitask.ts * Update task.json bumped version * Update task.loc.json bumped version * Update task.json * Typos and var type fixed * bumped the version * tested with bumbed version * fixed typo on Major version * fixed typo on Major version * Bumping AzureCLIV2 version to current sprint * Bumping AzureCLIV2 patch version * Bumping AzureCLIV2 patch version * Bumping AzureCLIV2 patch version * Bump task version and add node 20 generated files --------- Co-authored-by: Maxim Zaytsev <[email protected]> Co-authored-by: Vladyslav Horbachov <[email protected]> Co-authored-by: Vladyslav Horbachov <[email protected]>
1 parent 6c63082 commit 5278dc6

File tree

13 files changed

+116
-23
lines changed

13 files changed

+116
-23
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"loc.input.help.failOnStandardError": "If this is true, this task will fail when any errors are written to the StandardError stream. Unselect the checkbox to ignore standard errors and rely on exit codes to determine the status",
3030
"loc.input.label.powerShellIgnoreLASTEXITCODE": "Ignore $LASTEXITCODE",
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.",
32+
"loc.input.label.visibleAzLogin": "az login output visibility",
33+
"loc.input.help.visibleAzLogin": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
3234
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
3335
"loc.messages.ScriptFailed": "Script failed with error: %s",
3436
"loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",

Tasks/AzureCLIV2/azureclitask.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class azureclitask {
142142
private static async loginAzureRM(connectedService: string):Promise<void> {
143143
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, true);
144144
var subscriptionID: string = tl.getEndpointDataParameter(connectedService, "SubscriptionID", true);
145+
var visibleAzLogin: boolean = tl.getBoolInput("visibleAzLogin", true);
145146

146147
if (authScheme.toLowerCase() == "workloadidentityfederation") {
147148
var servicePrincipalId: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
@@ -187,11 +188,21 @@ export class azureclitask {
187188
let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
188189
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
189190
//login using svn
190-
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
191+
if (visibleAzLogin) {
192+
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
193+
}
194+
else {
195+
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions --output none`), tl.loc("LoginFailed"));
196+
}
191197
}
192198
else if(authScheme.toLowerCase() == "managedserviceidentity") {
193199
//login using msi
194-
Utility.throwIfError(tl.execSync("az", "login --identity"), tl.loc("MSILoginFailed"));
200+
if (visibleAzLogin) {
201+
Utility.throwIfError(tl.execSync("az", "login --identity"), tl.loc("MSILoginFailed"));
202+
}
203+
else {
204+
Utility.throwIfError(tl.execSync("az", "login --identity --output none"), tl.loc("MSILoginFailed"));
205+
}
195206
}
196207
else {
197208
throw tl.loc('AuthSchemeNotSupported', authScheme);

Tasks/AzureCLIV2/task.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"version": {
2121
"Major": 2,
2222
"Minor": 239,
23-
"Patch": 2
23+
"Patch": 4
2424
},
2525
"minimumAgentVersion": "2.0.0",
2626
"instanceNameFormat": "Azure CLI $(scriptPath)",
@@ -171,7 +171,16 @@
171171
"visibleRule": "scriptType = ps || scriptType = pscore",
172172
"helpMarkDown": "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.",
173173
"groupName": "advanced"
174-
}
174+
},
175+
{
176+
"name": "visibleAzLogin",
177+
"type": "boolean",
178+
"label": "az login output visibility",
179+
"defaultValue": "true",
180+
"required": false,
181+
"helpMarkDown": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
182+
"groupName": "advanced"
183+
}
175184
],
176185
"execution": {
177186
"Node10": {

Tasks/AzureCLIV2/task.loc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"version": {
2121
"Major": 2,
2222
"Minor": 239,
23-
"Patch": 2
23+
"Patch": 4
2424
},
2525
"minimumAgentVersion": "2.0.0",
2626
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
@@ -171,6 +171,15 @@
171171
"visibleRule": "scriptType = ps || scriptType = pscore",
172172
"helpMarkDown": "ms-resource:loc.input.help.powerShellIgnoreLASTEXITCODE",
173173
"groupName": "advanced"
174+
},
175+
{
176+
"name": "visibleAzLogin",
177+
"type": "boolean",
178+
"label": "ms-resource:loc.input.label.visibleAzLogin",
179+
"defaultValue": "true",
180+
"required": false,
181+
"helpMarkDown": "ms-resource:loc.input.help.visibleAzLogin",
182+
"groupName": "advanced"
174183
}
175184
],
176185
"execution": {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|2.239.2
2-
Node20_229_2|2.239.3
1+
Default|2.239.4
2+
Node20_229_2|2.239.5

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"loc.input.help.failOnStandardError": "If this is true, this task will fail when any errors are written to the StandardError stream. Unselect the checkbox to ignore standard errors and rely on exit codes to determine the status",
3030
"loc.input.label.powerShellIgnoreLASTEXITCODE": "Ignore $LASTEXITCODE",
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.",
32+
"loc.input.label.visibleAzLogin": "az login output visibility",
33+
"loc.input.help.visibleAzLogin": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
3234
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
3335
"loc.messages.ScriptFailed": "Script failed with error: %s",
3436
"loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",

_generated/AzureCLIV2/azureclitask.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class azureclitask {
142142
private static async loginAzureRM(connectedService: string):Promise<void> {
143143
var authScheme: string = tl.getEndpointAuthorizationScheme(connectedService, true);
144144
var subscriptionID: string = tl.getEndpointDataParameter(connectedService, "SubscriptionID", true);
145+
var visibleAzLogin: boolean = tl.getBoolInput("visibleAzLogin", true);
145146

146147
if (authScheme.toLowerCase() == "workloadidentityfederation") {
147148
var servicePrincipalId: string = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
@@ -187,11 +188,21 @@ export class azureclitask {
187188
let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
188189
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
189190
//login using svn
190-
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
191+
if (visibleAzLogin) {
192+
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
193+
}
194+
else {
195+
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" --password="${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions --output none`), tl.loc("LoginFailed"));
196+
}
191197
}
192198
else if(authScheme.toLowerCase() == "managedserviceidentity") {
193199
//login using msi
194-
Utility.throwIfError(tl.execSync("az", "login --identity"), tl.loc("MSILoginFailed"));
200+
if (visibleAzLogin) {
201+
Utility.throwIfError(tl.execSync("az", "login --identity"), tl.loc("MSILoginFailed"));
202+
}
203+
else {
204+
Utility.throwIfError(tl.execSync("az", "login --identity --output none"), tl.loc("MSILoginFailed"));
205+
}
195206
}
196207
else {
197208
throw tl.loc('AuthSchemeNotSupported', authScheme);

_generated/AzureCLIV2/task.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"version": {
2121
"Major": 2,
2222
"Minor": 239,
23-
"Patch": 2
23+
"Patch": 4
2424
},
2525
"minimumAgentVersion": "2.0.0",
2626
"instanceNameFormat": "Azure CLI $(scriptPath)",
@@ -171,6 +171,15 @@
171171
"visibleRule": "scriptType = ps || scriptType = pscore",
172172
"helpMarkDown": "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.",
173173
"groupName": "advanced"
174+
},
175+
{
176+
"name": "visibleAzLogin",
177+
"type": "boolean",
178+
"label": "az login output visibility",
179+
"defaultValue": "true",
180+
"required": false,
181+
"helpMarkDown": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
182+
"groupName": "advanced"
174183
}
175184
],
176185
"execution": {
@@ -204,7 +213,7 @@
204213
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
205214
},
206215
"_buildConfigMapping": {
207-
"Default": "2.239.2",
208-
"Node20_229_2": "2.239.3"
216+
"Default": "2.239.4",
217+
"Node20_229_2": "2.239.5"
209218
}
210219
}

_generated/AzureCLIV2/task.loc.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"version": {
2121
"Major": 2,
2222
"Minor": 239,
23-
"Patch": 2
23+
"Patch": 4
2424
},
2525
"minimumAgentVersion": "2.0.0",
2626
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
@@ -171,6 +171,15 @@
171171
"visibleRule": "scriptType = ps || scriptType = pscore",
172172
"helpMarkDown": "ms-resource:loc.input.help.powerShellIgnoreLASTEXITCODE",
173173
"groupName": "advanced"
174+
},
175+
{
176+
"name": "visibleAzLogin",
177+
"type": "boolean",
178+
"label": "ms-resource:loc.input.label.visibleAzLogin",
179+
"defaultValue": "true",
180+
"required": false,
181+
"helpMarkDown": "ms-resource:loc.input.help.visibleAzLogin",
182+
"groupName": "advanced"
174183
}
175184
],
176185
"execution": {
@@ -204,7 +213,7 @@
204213
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
205214
},
206215
"_buildConfigMapping": {
207-
"Default": "2.239.2",
208-
"Node20_229_2": "2.239.3"
216+
"Default": "2.239.4",
217+
"Node20_229_2": "2.239.5"
209218
}
210219
}

_generated/AzureCLIV2_Node20/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"loc.input.help.failOnStandardError": "If this is true, this task will fail when any errors are written to the StandardError stream. Unselect the checkbox to ignore standard errors and rely on exit codes to determine the status",
3030
"loc.input.label.powerShellIgnoreLASTEXITCODE": "Ignore $LASTEXITCODE",
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.",
32+
"loc.input.label.visibleAzLogin": "az login output visibility",
33+
"loc.input.help.visibleAzLogin": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
3234
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
3335
"loc.messages.ScriptFailed": "Script failed with error: %s",
3436
"loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",

0 commit comments

Comments
 (0)