Skip to content

Commit

Permalink
M168: Support for Azure Management Group in Azure CLI V2 task (#12922) (
Browse files Browse the repository at this point in the history
#12946)

* Support Azure CLI login for AzureAD and Azure DevOps (#12516)

* 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>

* Support for Azure Management Group in Azure CLI V2 task (#12922)

* Support for management group in Azure CLI

* Updating text

* Review comments

* Updating task version

Co-authored-by: Mike Brancato <mbrancato@users.noreply.github.com>
Co-authored-by: Mike Brancato <mbrancato@humana.com>
  • Loading branch information
3 people authored May 20, 2020
1 parent e35faa6 commit 2f534e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"loc.instanceNameFormat": "Azure CLI $(scriptPath)",
"loc.releaseNotes": "What's new in Version 2.0:\n- Support for PowerShell and PowerShell Core script. \n- PowerShell Core works with cross-platform agents (Linux, macOS, or Windows), make sure the agent has PowerShell version 6 or more. \n- Powershell script works with only Windows agent, make sure the agent has PowerShell version 5 or below.",
"loc.group.displayName.advanced": "Advanced",
"loc.input.label.connectedServiceNameARM": "Azure subscription",
"loc.input.help.connectedServiceNameARM": "Select an Azure resource manager subscription for the deployment",
"loc.input.label.connectedServiceNameARM": "Azure Resource Manager connection",
"loc.input.help.connectedServiceNameARM": "Select an Azure Resource Manager service connection for the deployment",
"loc.input.label.scriptType": "Script Type",
"loc.input.help.scriptType": "Type of script: PowerShell/PowerShell Core/Bat/Shell script. Select Shell/PowerShell Core script when running on Linux agent or Batch/PowerShell/PowerShell Core script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows).",
"loc.input.label.scriptLocation": "Script Location",
Expand Down
10 changes: 6 additions & 4 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,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 @@ -145,8 +145,10 @@ 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 @@ -189,4 +191,4 @@ if (!Utility.checkIfAzurePythonSdkIsInstalled()) {
tl.setResult(tl.TaskResult.Failed, tl.loc("AzureSDKNotFound"));
}

azureclitask.runMain();
azureclitask.runMain();
10 changes: 5 additions & 5 deletions 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": 12
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand All @@ -39,11 +39,11 @@
"azureSubscription"
],
"type": "connectedService:AzureRM",
"label": "Azure subscription",
"label": "Azure Resource Manager connection",
"required": true,
"helpMarkDown": "Select an Azure resource manager subscription for the deployment",
"helpMarkDown": "Select an Azure Resource Manager service connection for the deployment",
"properties": {
"EndpointFilterRule": "ScopeLevel != ManagementGroup"
"EndpointFilterRule": ""
}
},
{
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'"
}
}
}
4 changes: 2 additions & 2 deletions 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": 12
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand All @@ -43,7 +43,7 @@
"required": true,
"helpMarkDown": "ms-resource:loc.input.help.connectedServiceNameARM",
"properties": {
"EndpointFilterRule": "ScopeLevel != ManagementGroup"
"EndpointFilterRule": ""
}
},
{
Expand Down

0 comments on commit 2f534e9

Please sign in to comment.