Matrix Azure管道数据驱动矩阵
在GitHub操作中,我可以编写如下矩阵作业:Matrix Azure管道数据驱动矩阵,matrix,azure-pipelines,github-actions,azure-pipelines-yaml,Matrix,Azure Pipelines,Github Actions,Azure Pipelines Yaml,在GitHub操作中,我可以编写如下矩阵作业: jobs: test: name: Test-${{matrix.template}}-${{matrix.os}} runs-on: ${{matrix.os}} strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] template: ['API', 'GraphQL', 'Orleans',
jobs:
test:
name: Test-${{matrix.template}}-${{matrix.os}}
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
template: ['API', 'GraphQL', 'Orleans', 'NuGet']
steps:
#...
这将运行操作系统
和模板
的每个组合。在Azure管道中,您必须手动指定每个组合,如下所示:
stages:
- stage: Test
jobs:
- job: Test
strategy:
matrix:
Linux:
os: ubuntu-latest
template: API
Mac:
os: macos-latest
template: API
Windows:
os: windows-latest
template: API
# ...continued
pool:
vmImage: $(os)
timeoutInMinutes: 20
steps:
#...
是否可以创建类似于GitHub操作的数据驱动矩阵策略?不是理想的解决方案,但现在,您可以循环使用参数。编写一个如下所示的模板,并将数据传递给它 作业循环模板 参数: 职位:[] 工作: -${{parameters.jobs}}中的每个作业:#每个作业 -${{job}中的每对:#插入除“步骤”之外的所有属性 ${{如果ne(pair.key,'steps')}: ${pair.key}}:${{pair.value} 步骤:#将步骤包装起来 -任务:SetupMyBuildTools@1#预步骤 -${{job.steps}}#用户步骤 -任务:PublishMyTelemetry@1#立柱台阶 条件:始终() 有关更多示例,请参见此处: 是否可以创建类似于GitHub操作的数据驱动矩阵策略 答案是肯定的。这是github上已报告的已知问题: 此外,还有一种变通方法在以下文件中提到了此问题: 注 矩阵语法不支持自动作业缩放,但您可以 使用each关键字实现类似的功能。为了 例如,请参见 azure-pipelines-windows.yml:
jobs:
- ${{ each image in parameters.images }}:
- ${{ each pythonVersion in parameters.pythonVersions }}:
- ${{ each swVersion in parameters.swVersions }}:
- job:
displayName: ${{ format('OS:{0} PY:{1} SW:{2}', image, pythonVersion, swVersion) }}
pool:
vmImage: ${{ image }}
steps:
- script: echo OS version &&
wmic os get version &&
echo Lets test SW ${{ swVersion }} on Python ${{ pythonVersion }}
jobs:
- ${{ each image in parameters.images }}:
- ${{ each pythonVersion in parameters.pythonVersions }}:
- ${{ each swVersion in parameters.swVersions }}:
- job:
displayName: ${{ format('OS:{0} PY:{1} SW:{2}', image, pythonVersion, swVersion) }}
pool:
vmImage: ${{ image }}
steps:
- script: echo OS version &&
wmic os get version &&
echo Lets test SW ${{ swVersion }} on Python ${{ pythonVersion }}