我们希望创建一个管道来更新我们的多租户 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 来获取租户,并展开tenants
参数时Update_Tenants
阶段启动,但据我所知,这是不支持的,因为参数扩展是在管道启动时完成的。
-
一个不太理想但仍然可行的选项是创建一个包含租户的变量组 yaml 文件,并将此变量组包含在我的管道中,然后使用${{ variables.Tenants }}
引用它们的语法。但是,由于某种原因,变量只能是字符串。
我目前能想到的唯一解决方案是创建一个调用 REST api 的管道来让租户更新,然后使用天蓝色 devops api https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.1使用正确的参数值对实际更新过程进行排队。但这感觉像是一个有点笨拙的解决方法来完成这个任务。
现在我的问题是,有没有(更好的?)替代方案来完成我想做的事情?
也许这会有所帮助。我能够使用外部源(.txt 文件)来填充天蓝色管道中的数组变量。
工作示例
# 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)
来源(还有矩阵的示例)
其他来源
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)