Skip to content

Commit

Permalink
Azure/login should logout the active account at the beginning (#376)
Browse files Browse the repository at this point in the history
* logout at the beginning

* remove logout step in test case
  • Loading branch information
MoChilia authored Nov 27, 2023
1 parent 34b958d commit 40935f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/azure-login-negative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ jobs:
script: |
core.setFailed('Last action should fail but not. Please check it.')
# logout first to avoid the conflict with SP1
- name: Azure CLI logout
run: |
az logout
# SP1 is ignored and SP2 will be used for login, but it will fail since SP2 has no access to the given subscription
- name: Login with both creds and individual parameters
id: login_12
Expand Down
7 changes: 7 additions & 0 deletions src/Cli/AzureCliLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export class AzureCliLogin {
await this.executeAzCliCommand(["--version"], true, execOptions);
core.debug(`Azure CLI version used:\n${output}`);

try {
await this.executeAzCliCommand(["logout"], true, execOptions);
}
catch (error) {
core.debug(`Ignore logout error: "${error}"`);
}

this.setAzurestackEnvIfNecessary();

await this.executeAzCliCommand(["cloud", "set", "-n", this.loginConfig.environment], false);
Expand Down

0 comments on commit 40935f9

Please sign in to comment.