Skip to content

Commit 696966e

Browse files
authored
Fix issue #12237 - fails when service principal key contains quotes (#12290)
* Fix issue #12237 - fails when service principal key contains quotes (#12260) * Fix issue #12237 - fails when service principal key contains quotes * Fix issue #12266: powershellIgnoreLASTEXITCODE not working (#12286)
1 parent 892082c commit 696966e

File tree

7 files changed

+11
-7
lines changed

7 files changed

+11
-7
lines changed

Tasks/AzureCLIV1/azureclitask.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ export class azureclitask {
144144
this.servicePrincipalKey = cliPassword;
145145
}
146146

147+
let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
148+
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
147149
//login using svn
148-
this.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
150+
this.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}"`), tl.loc("LoginFailed"));
149151
}
150152
else if(authScheme.toLowerCase() == "managedserviceidentity") {
151153
//login using msi

Tasks/AzureCLIV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"demands": [],
2020
"version": {
2121
"Major": 1,
22-
"Minor": 157,
22+
"Minor": 163,
2323
"Patch": 0
2424
},
2525
"minimumAgentVersion": "2.0.0",

Tasks/AzureCLIV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"demands": [],
2020
"version": {
2121
"Major": 1,
22-
"Minor": 157,
22+
"Minor": 163,
2323
"Patch": 0
2424
},
2525
"minimumAgentVersion": "2.0.0",

Tasks/AzureCLIV2/azureclitask.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ export class azureclitask {
102102
this.servicePrincipalKey = cliPassword;
103103
}
104104

105+
let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
106+
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
105107
//login using svn
106-
Utility.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
108+
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}"`), tl.loc("LoginFailed"));
107109
}
108110
else if(authScheme.toLowerCase() == "managedserviceidentity") {
109111
//login using msi

Tasks/AzureCLIV2/src/Utility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class Utility {
5656
}
5757
contents.push(content.trim());
5858

59-
let powerShellIgnoreLASTEXITCODE: string = tl.getInput('powerShellIgnoreLASTEXITCODE', false);
59+
let powerShellIgnoreLASTEXITCODE: boolean = tl.getBoolInput('powerShellIgnoreLASTEXITCODE', false);
6060
if (!powerShellIgnoreLASTEXITCODE) {
6161
contents.push(`if (!(Test-Path -LiteralPath variable:\LASTEXITCODE)) {`);
6262
contents.push(` Write-Host '##vso[task.debug]$LASTEXITCODE is not set.'`);

Tasks/AzureCLIV2/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"version": {
2222
"Major": 2,
2323
"Minor": 0,
24-
"Patch": 5
24+
"Patch": 7
2525
},
2626
"minimumAgentVersion": "2.0.0",
2727
"instanceNameFormat": "Azure CLI $(scriptPath)",

Tasks/AzureCLIV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"version": {
2222
"Major": 2,
2323
"Minor": 0,
24-
"Patch": 5
24+
"Patch": 7
2525
},
2626
"minimumAgentVersion": "2.0.0",
2727
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",

0 commit comments

Comments
 (0)