不。服务连接无法动态生成。在管道开始运行之前,必须解析和验证服务连接引用。
更新:由于这是经典版本,因此必须事先知道服务连接。在 YAML 中,可以在编译时加载它。我知道执行此操作的唯一方法是通过 YAML 管道中的 ADO 变量模板文件。 这是如何操作的链接
这里是关于 在经典版本中使用自定义变量
的 MS 文档就我而言,我需要使用存储在变量组中的客户端 ID 和 clinet 密钥。所以我使用了 Bash 任务的
env
变量组:
使用服务主体客户端 ID 和密钥定义变量组:
通过 bash 任务的
env
引用变量:
variables:
- group: Bicep Auth Variables
steps:
- bash: |
# Write your commands here
echo "Client ID is : $client_id"
echo "Client Secret is length is:"
echo $client_secret | wc -m
echo "Subscription ID is : $subscription_id"
echo "Tenant ID is : $tenant_id"
# Authenticate with Azure Cloud
echo "Authenticating with Azure..."
az login --service-principal --username $client_id --password $client_secret --tenant $tenant_id
echo "Az Login command finished. Now setting up Subscription..."
az account set --subscription $subscription_id
echo "Az Account set command finished"
az account show
echo "Az Account Show command finished"
workingDirectory: ./storage-accounts
displayName: 'Az Cli Auth'
env:
client_id: $(BICEP_CLIENT_ID)
client_secret: $(BICEP_CLIENT_SECRET)
subscription_id: $(BICEP_SUBSCRIPTION_ID)
tenant_id: $(BICEP_TENANT_ID)