Skip to content

Commit

Permalink
Setting up Azure Active cloud corresponding to service endpoint (#9003)…
Browse files Browse the repository at this point in the history
… (#9006)

* Setting up Azure Active cloud corresponding to service endpoint

* Fix review comment
  • Loading branch information
vineetmimrot authored Dec 5, 2018
1 parent c33a2f3 commit 8ebe8db
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"loc.messages.FailedToLogout": "The following error occurred while logging out: %s",
"loc.messages.LoginFailed": "Azure login failed",
"loc.messages.ErrorInSettingUpSubscription": "Error in setting up subscription",
"loc.messages.SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s"
"loc.messages.SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s",
"loc.messages.SettingAzureCloud": "Setting active cloud to: %s"
}
19 changes: 13 additions & 6 deletions Tasks/AzureCLIV1/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export class azureclitask {
tool = tl.tool(tl.which(scriptPath, true));
}
this.throwIfError(tl.execSync("az", "--version"));
this.useGlobalConfig = tl.getBoolInput("useGlobalConfig");
// set az cli config dir
this.setConfigDirectory();
this.setAzureCloudBasedOnServiceEndpoint();
this.loginAzure();

tool.line(args); // additional args should always call line. line() parses quoted arg strings
Expand Down Expand Up @@ -104,7 +106,6 @@ export class azureclitask {
private static isLoggedIn: boolean = false;
private static cliPasswordPath: string = null;
private static azCliConfigPath: string;
private static useGlobalConfig: boolean = true;

private static loginAzure() {
var connectedService: string = tl.getInput("connectedServiceNameARM", true);
Expand All @@ -131,9 +132,6 @@ export class azureclitask {
var tenantId: string = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
var subscriptionID: string = tl.getEndpointDataParameter(connectedService, "SubscriptionID", true);

// set az cli config dir
this.setConfigDirectory();

//login using svn
this.throwIfError(tl.execSync("az", "login --service-principal -u \"" + servicePrincipalId + "\" -p \"" + cliPassword + "\" --tenant \"" + tenantId + "\""), tl.loc("LoginFailed"));
this.isLoggedIn = true;
Expand All @@ -142,7 +140,7 @@ export class azureclitask {
}

private static setConfigDirectory(): void {
if (this.useGlobalConfig) {
if (tl.getBoolInput("useGlobalConfig")) {
return;
}

Expand All @@ -162,6 +160,15 @@ export class azureclitask {
}
}

private static setAzureCloudBasedOnServiceEndpoint(): void {
var connectedService: string = tl.getInput("connectedServiceNameARM", true);
var environment = tl.getEndpointDataParameter(connectedService, 'environment', true);
if(!!environment) {
console.log(tl.loc('SettingAzureCloud', environment));
this.throwIfError(tl.execSync("az", "cloud set -n " + environment));
}
}

private static logoutAzure() {
try {
tl.execSync("az", " account clear");
Expand Down
7 changes: 4 additions & 3 deletions Tasks/AzureCLIV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 143,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -94,7 +94,7 @@
"name": "useGlobalConfig",
"type": "boolean",
"label": "Use global Azure CLI configuration",
"defaultValue": "true",
"defaultValue": "false",
"required": false,
"helpMarkDown": "If this is false, this task will use its own separate [Azure CLI configuration directory](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file). This can be used to run Azure CLI tasks in *parallel* releases",
"groupName": "advanced"
Expand Down Expand Up @@ -135,6 +135,7 @@
"FailedToLogout": "The following error occurred while logging out: %s",
"LoginFailed": "Azure login failed",
"ErrorInSettingUpSubscription": "Error in setting up subscription",
"SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s"
"SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s",
"SettingAzureCloud": "Setting active cloud to: %s"
}
}
7 changes: 4 additions & 3 deletions Tasks/AzureCLIV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 143,
"Patch": 4
"Patch": 5
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -94,7 +94,7 @@
"name": "useGlobalConfig",
"type": "boolean",
"label": "ms-resource:loc.input.label.useGlobalConfig",
"defaultValue": "true",
"defaultValue": "false",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.useGlobalConfig",
"groupName": "advanced"
Expand Down Expand Up @@ -135,6 +135,7 @@
"FailedToLogout": "ms-resource:loc.messages.FailedToLogout",
"LoginFailed": "ms-resource:loc.messages.LoginFailed",
"ErrorInSettingUpSubscription": "ms-resource:loc.messages.ErrorInSettingUpSubscription",
"SettingAzureConfigDir": "ms-resource:loc.messages.SettingAzureConfigDir"
"SettingAzureConfigDir": "ms-resource:loc.messages.SettingAzureConfigDir",
"SettingAzureCloud": "ms-resource:loc.messages.SettingAzureCloud"
}
}

0 comments on commit 8ebe8db

Please sign in to comment.