Skip to content

When AZURE_CONFIG_DIR is set, login context gets cleared by setting random_config_dir=True #28668

@jiasli

Description

@jiasli

ADO's Azure CLI task contains this step:

Setting AZURE_CONFIG_DIR env variable to: /mnt/vss/_work/_temp/.azclitask

In Knack, the config dir specified by env var takes higher precedence:

https://github.com/microsoft/knack/blob/e0c14114aea5e4416c70a77623e403773aba73a8/knack/config.py#L44

        self.config_dir = os.environ.get('{}CONFIG_DIR'.format(env_var_prefix), default_config_dir)

So when AZURE_CONFIG_DIR is set, setting config_dir becomes a no-op for AzCli:

super(DummyCli, self).__init__(
cli_name='az',
config_dir=config_dir,

self.config.config_dir in this case is the value of AZURE_CONFIG_DIR (/mnt/vss/_work/_temp/.azclitask).

During tearDown, directory specified by AZURE_CONFIG_DIR gets deleted:

def tearDown(self):
for processor in self._processors_to_reset:
processor.reset()
if self.random_config_dir:
from azure.cli.core.util import rmtree_with_retry
rmtree_with_retry(self.cli_ctx.config.config_dir)

This causes failure in the following azdev test --live command:

self = <azure.cli.core._profile.Profile object at 0x7f3d731794b0>
subscription = None

    def get_subscription(self, subscription=None):  # take id or name
        subscriptions = self.load_cached_subscriptions()
        if not subscriptions:
>           raise CLIError(_AZ_LOGIN_MESSAGE)
E           knack.util.CLIError: Please run 'az login' to setup account.

src/azure-cli-core/azure/cli/core/_profile.py:546: CLIError

Introduced by #25689

Discovered while working on #28660

Metadata

Metadata

Assignees

Labels

Accountaz login/accountAuto-AssignAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions