Azure devops 从外部源填充运行时azure管道参数

Azure devops 从外部源填充运行时azure管道参数,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,我们希望创建一个管道来更新我们的多租户azure环境。我们需要在每个租户的更新过程中执行一些操作。为了实现这一点,我们希望为每个租户创建一个作业,这样我们就可以并行处理租户。为此,我希望使用一个运行时参数将要更新的租户传递到我的管道,如下所示: parameters: - name: tenants type: object 租户参数的值可能如下所示: - Name: "customer1" Someotherproperty: "some value&q

我们希望创建一个管道来更新我们的多租户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) 
要生成作业,我们需要执行以下操作:

- 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\u Tenants
    阶段之前放置一个构建阶段,以调用REST api来获取租户,并在
    Update\u Tenants
    阶段启动时展开
    Tenants
    参数,但这是不受支持的,因为参数扩展是在管道启动时完成的

  • 一个不太理想但仍然可行的选项是创建一个包含租户的变量组yaml文件,并将该变量组包含在我的管道中,并使用
    ${{variables.tenants}
    语法引用它们。但是,由于某些原因,变量只能是字符串

我目前能想到的唯一解决方案是创建一个调用REST api的管道,让租户进行更新,然后使用队列将实际的更新过程与正确的参数值一起排队。但要做到这一点,这感觉有点笨重

现在我的问题是,有没有更好的选择来完成我想做的事情

为了实现这一点,我们希望为每个租户创建一个作业,因此 可以并行处理租户

除了滚动部署策略外,您还可以检查

除非必须使用运行时参数,否则可以尝试以下操作:

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变量为$(列表图像)
来源(还有矩阵示例)
其他来源

问题是,我不想硬编码管道中的租户,但使用此类策略的唯一方法是使用运行时参数,因为这是影响作业扩展的唯一方法。矩阵加上运行时参数可能已经让我的解决方案变得更好了,但仍然需要我首先启动一个不同的管道,以便能够使用正确的参数调用我的管道。我已经测试过,使用矩阵确实让它变得更好了,因为现在我可以控制正在执行的最大并行作业。但是,我仍然需要一些方法来填充租户参数(原始问题)。据我所知,它必须是一个参数,否则我无法正确地展开矩阵。这里是关于从对象到字符串的类型转换。看起来你不能以这种方式使用其他财产。谢谢你调查,但我不知道这对我有什么帮助。我需要某种方法在管道本身中指定运行时参数,而不是将对象转换为字符串。我认为使用Api的解决方案是实现我所希望的唯一途径。问题是我需要为每个租户运行一个作业。基于变量创建矩阵似乎不可能,因此您的解决方案对我不起作用。我们坚持使用API将实际管道与正确的参数值排队,直到找到更好的解决方案