将矩阵定义为多阶段 yaml 管道中的变量

def*_*rtd 5 yaml azure-devops azure-pipelines

我正在创建一个多阶段的 Azure DevOps (yaml) 管道,该管道使用对其他模板的多个引用。正如您在下面的管道中看到的,我必须为我的build-client-steps.ymldistribute-client-steps.yml文件提供相同的矩阵。该矩阵用于我的管道策略。

有没有办法将此矩阵声明为我的文件的变量azure-pipelines.yml

stages:
- stage: build
  displayName: Build & validate
  jobs:
    - template: pipelines/templates/build-client-steps.yml
      parameters:
        matrix:
          base-ios-prod:
            app: string
            artifact: string
            variant: string
            os: ios
            distribution: string
          base-android-prod:
            app: string
            artifact: string
            variant: string
            os: android
            distribution: string
        keystore_password: '$(keystore_password)'
        keystore_alias: '$(keystore_alias)'
        APPLE_CERTIFICATE_SIGNING_IDENTITY: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
        APPLE_PROV_PROFILE_UUID: '$(APPLE_PROV_PROFILE_UUID)'
        teamId: '$(teamId)'
        P12Password: '$(P12Password)'         
    - template: pipelines/templates/build-server-steps.yml
    - template: pipelines/templates/build-infra-steps.yml
    - template: pipelines/templates/build-sap-steps.yml
- stage: prepareBase
  displayName: Prepare base infra
  dependsOn: build
  jobs:
    - template: pipelines/templates/deploy-infra-jobs.yml
      parameters:
        parameterFile: string
        resourceGroup: string
- stage: deployBase
  displayName: Deploy base
  dependsOn: prepareBase
  jobs:
    - template: pipelines/templates/deploy-server-jobs.yml
      parameters:
        resourceGroup: string
- stage: activateBase
  displayName: Activate base
  dependsOn: deployBase
  jobs:
    - template: pipelines/templates/swap-app-jobs.yml
      parameters:
        parameterFile: string
        resourceGroup: string
    - template: pipelines/templates/distribute-client-jobs.yml
      parameters:
        matrix:
          base-ios-prod:
            app: string
            artifact: string
            variant: string
            os: ios
            distribution: string
          base-android-prod:
            app: string
            artifact: string
            variant: string
            os: android
            distribution: string
Run Code Online (Sandbox Code Playgroud)

Hug*_*Lin 1

有没有办法将此矩阵声明为我的 azure-pipelines.yml 文件的变量?

对于这个问题,据我所知,这在yaml管道中是不可行的。本文档中有这样一句话:由于变量在作业开始时扩展,因此不能在策略中使用它们。因此,即使您可以将矩阵定义为变量,也无法在策略中引用它。

另外,你的build-client-steps.ymldistribute-client-steps.yml文件应该是作业模板,那么你应该能够将矩阵写入作业模板。这样,您只需要引用azure-pipelines.yml文件中的作业模板即可。