Azure devops 从外部源填充运行时azure管道参数
我们希望创建一个管道来更新我们的多租户azure环境。我们需要在每个租户的更新过程中执行一些操作。为了实现这一点,我们希望为每个租户创建一个作业,这样我们就可以并行处理租户。为此,我希望使用一个运行时参数将要更新的租户传递到我的管道,如下所示:Azure devops 从外部源填充运行时azure管道参数,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,我们希望创建一个管道来更新我们的多租户azure环境。我们需要在每个租户的更新过程中执行一些操作。为了实现这一点,我们希望为每个租户创建一个作业,这样我们就可以并行处理租户。为此,我希望使用一个运行时参数将要更新的租户传递到我的管道,如下所示: parameters: - name: tenants type: object 租户参数的值可能如下所示: - Name: "customer1" Someotherproperty: "some value&q
parameters:
- name: tenants
type: object
租户参数的值可能如下所示:
- Name: "customer1"
Someotherproperty: "some value"
- Name: "customer2"
Someotherproperty: "some other value"
stages:
- stage:
jobs:
- job: Update_Tenant
strategy:
matrix:
${{ each tenant in parameters.Tenants }}:
${{ tenant.tenantName }}:
name: ${{ tenant.tenantName }}
someproperty: ${{ tenant.otherProperty }}
maxParallel: 2
steps:
- checkout: none
- script: echo $(name).$(someproperty)
要生成作业,我们需要执行以下操作:
- Name: "customer1"
Someotherproperty: "some value"
- Name: "customer2"
Someotherproperty: "some other value"
stages:
- stage:
jobs:
- job: Update_Tenant
strategy:
matrix:
${{ each tenant in parameters.Tenants }}:
${{ tenant.tenantName }}:
name: ${{ tenant.tenantName }}
someproperty: ${{ tenant.otherProperty }}
maxParallel: 2
steps:
- checkout: none
- script: echo $(name).$(someproperty)
现在我们需要的是某种方法来填充这个tenants
参数。现在我尝试了几种解决方案:
- 理想情况下,我希望在
阶段之前放置一个构建阶段,以调用REST api来获取租户,并在Update\u Tenants
阶段启动时展开Update\u Tenants
参数,但这是不受支持的,因为参数扩展是在管道启动时完成的Tenants
- 一个不太理想但仍然可行的选项是创建一个包含租户的变量组yaml文件,并将该变量组包含在我的管道中,并使用
语法引用它们。但是,由于某些原因,变量只能是字符串${{variables.tenants}
jobs:
- job: Update
strategy:
matrix:
tenant1:
Someotherproperty1: '1.1'
Someotherproperty2: '1.2'
tenant2:
Someotherproperty1: '2.1'
Someotherproperty2: '2.2'
tenant3:
Someotherproperty1: '3.1'
Someotherproperty2: '3.2'
maxParallel: 3
steps:
- checkout: none
- script: echo $(Someotherproperty1).$(Someotherproperty2)
displayName: 'Echo something'
也许这会有帮助。我能够使用外部源(.txt文件)填充azure管道中的数组变量 工作示例
#创建一个变量
-狂欢节:|
arrVar=()
对于“cat my_images.txt”中的图像;做
arrVar+=$images
arrVar+=“,”
完成;
echo“##vso[task.setvariable=list_images]$arrVar”
#使用变量
#“$(list_images)”由Azure Pipelines替换为`list_images`变量的内容
#在将脚本主体交给shell之前。
-狂欢节:|
echo my pipeline变量为$(列表图像)
来源(还有矩阵示例)