我已使用我的帐户“emj”登录并在 Jenkins 上执行了以下 Azure CLI
az account show
az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-123>>
az account show
下面是输出
它按预期显示了用户帐户
+ az account show
{
"environmentName": "AzureCloud",
"homeTenantId": "tenantID",
"id": "Subscription-123-ID",
"isDefault": true,
"managedByTenants": [],
"name": "Subscription-123",
"state": "Enabled",
"tenantId": "tenantID",
"user": {
"name": "emj@demo.com",
"type": "user"
}
}
作为服务主体登录
[Pipeline] sh
+ az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
[
{
"cloudName": "AzureCloud",
"homeTenantId": "tenantID",
"id": "Subscription-456-ID",
"isDefault": true,
"managedByTenants": [],
"name": "Subscription-456",
"state": "Enabled",
"tenantId": "tenantID",
"user": {
"name": "servicePrincipalID",
"type": "servicePrincipal"
}
},
{
"cloudName": "AzureCloud",
"homeTenantId": "tenantID",
"id": "Subscription-789-ID",
"isDefault": false,
"managedByTenants": [
{
"tenantId": "tenantID"
}
],
"name": "Subscription-789",
"state": "Enabled",
"tenantId": "tenantID",
"user": {
"name": "servicePrincipalID",
"type": "servicePrincipal"
}
}
]
并设置所需的订阅
[Pipeline] sh
+ az account set -s <<Subscription-456-ID>>
当我期待显示服务主体时,它显示了用户帐户
[Pipeline] sh
+ az account show
{
"environmentName": "AzureCloud",
"homeTenantId": "tenantID",
"id": "Subscription-456-ID",
"isDefault": true,
"managedByTenants": [],
"name": "Subscription-456",
"state": "Enabled",
"tenantId": "tenantID",
"user": {
"name": "emj@demo.com",
"type": "user"
}
}
注意:如果不使用“az account set -s <>”设置订阅,则显示服务主体帐户。
为什么它显示用户帐户而不是服务主体?'az login --service-principal -u <> -p <> -t >' 是什么意思,因为它没有被考虑在内?