Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Cli/AzureCliLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class AzureCliLogin {
loginConfig: LoginConfig;
azPath: string;
loginOptions: ExecOptions;
azVersion: string;

constructor(loginConfig: LoginConfig) {
this.loginConfig = loginConfig;
Expand All @@ -30,7 +31,12 @@ export class AzureCliLogin {

await this.executeAzCliCommand(["version"], true, execOptions);
core.debug(`Azure CLI version used:\n${output}`);

try {
this.azVersion = JSON.parse(output)["azure-cli"];
}
catch (error) {
core.warning("Failed to parse Azure CLI version.");
}
await this.registerAzurestackEnvIfNecessary();

await this.executeAzCliCommand(["cloud", "set", "-n", this.loginConfig.environment], false);
Expand Down Expand Up @@ -108,7 +114,20 @@ export class AzureCliLogin {
}

async loginWithUserAssignedIdentity(args: string[]) {
args.push("--username", this.loginConfig.servicePrincipalId);
let azcliMinorVersion = 0;
try {
azcliMinorVersion = parseInt(this.azVersion.split('.')[1], 10);
}
catch (error) {
core.warning("Failed to parse the minor version of Azure CLI. Assuming the version is less than 2.69.0");
}
//From Azure-cli v2.69.0, `--username` is replaced with `--client-id`, `--object-id` or `--resource-id`: https://github.com/Azure/azure-cli/pull/30525
if (azcliMinorVersion < 69) {
args.push("--username", this.loginConfig.servicePrincipalId);
}
Comment on lines +125 to +127
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any schedule on when login action stops supporting Azure CLI < 2.69.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no plans to change. Telemetry shows that about 30% of users utilize self-hosted runners, which may not always install the latest Azure CLI. Additionally, all managed identity users are using Azure VMs. So I would like to continue supporting login action across different Azure CLI versions, similar to cli action.

else {
args.push("--client-id", this.loginConfig.servicePrincipalId);
}
await this.callCliLogin(args, 'user-assigned managed identity');
}

Expand Down
Loading