要处理的 az cli 登录会话范围

az cli login session scope to process

在 PowerShell 中,您可以执行以下操作:

$result = Connect-AzAccount `
  -SubscriptionId $SubscriptionId `
  -TenantId $TenantId `
  -Credential $credential `
  -ContextName $contextName `
  -Scope Process `
  -ServicePrincipal

根据 doc,如果您指定 -Scope Process,Az 上下文将绑定到特定的 PS 进程。

Determines the scope of context changes, for example, whether changes apply only to the current process, or to all sessions started by this user.

有什么方法可以用 az cli 复制这种行为吗?

我的用例 我将从 Jenkins 作业连接到 Azure。如果我开始两份工作,也许其中一份会通过 az logout -u <user> 断开连接并影响另一份工作。

我想隔离 az cli 会话。

不幸的是,Azure CLI 中没有 -Scope Process 这样的等效功能,所有可用参数都在这里。

https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az_login

我还没有亲自使用过它,但是根据this GitHub issue which links to this documentation,使用进程范围的环境变量应该是可能的。