我们希望创建一个管道来更新我们的 Multi-Tenancy Azure 环境。我们需要在更新每个租户期间执行一些操作。为此,我们希望为每个租户创建一个作业,以便我们可以并行处理租户。为此,我想使用运行时参数将租户传递到我的管道,如下所示:
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)
现在我们需要的是一些方法来填充此tenants
参数。现在我尝试了一些解决方案:
理想情况下,我想在
Update_Tenants
阶段之前放置一个构建阶段,以调用 REST api 来获取租户,并在Update_Tenants
阶段开始,但这不受 AFAIK 支持,因为参数扩展是在管道启动时完成的。一个不太理想但仍然可行的选择是创建一个包含租户的变量组 yaml 文件,并将这个变量组包含在我的管道中,并使用
${{ variables.Tenants }}
语法来引用它们。但是,由于某些原因,变量只能是字符串。
我目前能想到的唯一解决方案是创建一个调用 REST api 的管道来让租户更新,然后使用 azure devops api使用正确的参数值对实际更新过程进行排队。但这感觉像是一个有点笨拙的解决方法来实现这一点。
现在我的问题是,是否有任何(更好的?)替代方案来完成我想做的事情?
最佳答案
也许这会有所帮助。我能够使用外部源(.txt 文件)来填充 azure 管道中的数组变量。
工作示例
# Create a variable
- bash: |
arrVar=()
for images in `cat my_images.txt`;do
arrVar+=$images
arrVar+=","
done;
echo "##vso[task.setvariable variable=list_images]$arrVar"
# Use the variable
# "$(list_images)" is replaced by the contents of the `list_images` variable by Azure Pipelines
# before handing the body of the script to the shell.
- bash: |
echo my pipeline variable is $(list_images)
来源(也有矩阵的例子)
其他来源
关于azure-devops - 从外部源填充运行时 azure 管道参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63612133/