Skip to content

Commit

Permalink
Support Azure CLI login for AzureAD and Azure DevOps (#12516)
Browse files Browse the repository at this point in the history
* Support Azure CLI login for AzureAD and Azure DevOps

* Set subscription only if parameter is set

* Increment task version

Co-authored-by: Mike Brancato <mbrancato@humana.com>
Co-authored-by: Nitin Issac Joy <nijoy@microsoft.com>
  • Loading branch information
3 people committed May 20, 2020
1 parent 16f91d2 commit 763db7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class azureclitask {
let escapedCliPassword = cliPassword.replace(/"/g, '\\"');
tl.setSecret(escapedCliPassword.replace(/\\/g, '\"'));
//login using svn
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}"`), tl.loc("LoginFailed"));
Utility.throwIfError(tl.execSync("az", `login --service-principal -u "${servicePrincipalId}" -p "${escapedCliPassword}" --tenant "${tenantId}" --allow-no-subscriptions`), tl.loc("LoginFailed"));
}
else if(authScheme.toLowerCase() == "managedserviceidentity") {
//login using msi
Expand All @@ -139,8 +139,11 @@ export class azureclitask {
}

this.isLoggedIn = true;
//set the subscription imported to the current subscription
Utility.throwIfError(tl.execSync("az", "account set --subscription \"" + subscriptionID + "\""), tl.loc("ErrorInSettingUpSubscription"));

if (subscriptionID) {
//set the subscription imported to the current subscription
Utility.throwIfError(tl.execSync("az", "account set --subscription \"" + subscriptionID + "\""), tl.loc("ErrorInSettingUpSubscription"));
}
}

private static setConfigDirectory(): void {
Expand Down Expand Up @@ -183,4 +186,4 @@ if (!Utility.checkIfAzurePythonSdkIsInstalled()) {
tl.setResult(tl.TaskResult.Failed, tl.loc("AzureSDKNotFound"));
}

azureclitask.runMain();
azureclitask.runMain();
4 changes: 2 additions & 2 deletions Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 8
"Patch": 12
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -198,4 +198,4 @@
"GlobalCliConfigAgentVersionWarning": "For agent version < 2.115.0, only global Azure CLI configuration can be used",
"UnacceptedScriptLocationValue": "%s is not a valid value for task input 'Script Location' (scriptLocation in YAML). Value can either be'inlineScript' or 'scriptPath'"
}
}
}

0 comments on commit 763db7a

Please sign in to comment.