如何在 Azure Pipelines 中跨多个阶段传播矩阵定义

How to propgate matrix definition across multiple stages in Azure Pipelines

我正在 Azure Pipelines 中编写多阶段作业,其中涉及从脚本生成矩阵作为阶段的输出。我想跨多个阶段使用该矩阵来生成工作,但我想使用该矩阵的前一阶段的工作条件。

示例天蓝色-pipelines.yml:

stages:
- stage: A
  jobs: 
   - job: generateMatrix
- stage: B
  dependsOn: A
  jobs:
    - job: "" # This lets the job name be just the name of the matrix key
      continueOnError: true # steps in these jobs may or may not fail
      strategy:
        matrix: $[ stageDependencies.A.generateMatrix.outputs['matrix'] ]
- stage: C
  dependsOn: # Needs A's matrix and B job results
    - A
    - B
  jobs: 
    - job: "" # The job name here should be the same as in stage B
      continueOnError: true 
      strategy:
        matrix: $[ stageDependencies.A.generateMatrix.outputs['matrix'] ]
      steps:
        - script: echo "Job from Stage B Succeeded"
          condition: eq(stageDependencies.B.variables['Agent.JobName'].result, 'Succeeded')
        - script: echo "Job from Stage B Failed"
          condition: condition: ne(stageDependencies.B.variables['Agent.JobName'].result, 'Succeeded')

所以我需要能够执行以下操作之一:

有没有人知道如何做到这一点?我试过上面的但失败了。

恐怕我们不能在Stage B中修改Stage A输出的矩阵,你需要在Stage B中定义一个新的输出,然后在Stage C中使用。