首页 > 解决方案 > 如何在 Azure Pipelines 中跨多个阶段传播矩阵定义

问题描述

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

示例 azure-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')

所以我需要具备以下能力之一:

有谁知道如何做到这一点?我尝试了上述方法,但失败了。

标签: azureazure-devopsazure-pipelinesazure-pipelines-yaml

解决方案


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


推荐阅读