如何在Azure Pipelines中用矩阵变量设置对象类型代理池?
解决Azure Pipelines矩阵中Pool配置的问题
矩阵变量仅支持标量值,无法直接在矩阵中定义对象类型的Pool配置,可通过条件表达式+标量平台标识的方式实现需求,具体配置如下:
- job: Test strategy: matrix: linux: platform: linux windows: platform: windows mac: platform: mac pool: ${{ if eq(variables.platform, 'linux') }}: name: AzurePipelines-EO demands: - ImageOverride -equals AzurePipelinesUbuntu20.04compliantGPT os: Linux ${{ if eq(variables.platform, 'windows') }}: name: VSEngSS-MicroBuild2022-1ES ${{ if eq(variables.platform, 'mac') }}: name: Azure Pipelines vmImage: macOS-12 os: macOS
方案说明
- 矩阵中仅存储标量类型的
platform变量,标识当前运行的平台 - 在
pool节点使用Azure Pipelines的编译期条件表达式${{ if }},根据platform变量的值渲染对应平台的Pool配置 - 条件表达式在YAML编译阶段执行,每个矩阵维度会生成独立且符合要求的Pool结构,完全适配不同平台的配置差异
内容的提问来源于stack exchange,提问作者Andrew Arnott
相关产品推荐
相关产品推荐

