Azure 将变量组传递到服务连接

问题描述 投票:0回答:3

我想传递/访问链接到我的服务连接中的管道的变量组。我找不到任何文章或文档来说明如何执行此操作。

是否有其他方法可以使用变量组动态创建服务连接?

我需要变量的地方

enter image description here

变量所在位置

enter image description here

azure azure-devops azure-pipelines azure-pipelines-release-pipeline
3个回答
1
投票

不。服务连接无法动态生成。在管道开始运行之前,必须解析和验证服务连接引用。


0
投票

更新:由于这是经典版本,因此必须事先知道服务连接。在 YAML 中,可以在编译时加载它。我知道执行此操作的唯一方法是通过 YAML 管道中的 ADO 变量模板文件。 这是如何操作的链接

这里是关于 在经典版本中使用自定义变量

的 MS 文档

0
投票

就我而言,我需要使用存储在变量组中的客户端 ID 和 clinet 密钥。所以我使用了 Bash 任务的

env
变量组:

第 1 步:

使用服务主体客户端 ID 和密钥定义变量组:

Azure devops variable group

第 2 步:

通过 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)
© www.soinside.com 2019 - 2024. All rights reserved.