对于Azure管道yaml文件,我希望在特定池中的每个代理上运行一次任务集。当我查看就业策略矩阵时,它看起来是一个很好的解决方案,但目前它无法提取我为此使用的变量。
与此问题相关的管道yaml文件是以下部分:
resources:
- repo: self
trigger: none
jobs:
- job: RunOnEveryAgent
strategy:
maxParallel: 3
matrix:
agent_1:
agentName: Hosted Agent
agent_2:
agentName: Hosted VS2017 2
agent_3:
agentName: Hosted VS2017 3
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
- Agent.Name -equals $(agentName)
steps:
- (etc.)使用此脚本,我尝试设置一个矩阵,以便在池中的三个代理中各运行一次。然而,当我试图引用需求列表中的代理时,它不会捡到它。实际错误消息如下:
错误1在池托管的VS2017中找不到满足指定要求的代理: msbuild 可视化演播室 Agent.Name -equals $(agentName) Agent.Version -gtVersion 2.141.1
如果我硬编码代理名称,它就会工作:
demands:
- msbuild
- visualstudio
- Agent.Name Hosted VS2017 3是否支持在池需求中使用这些变量?还是应该使用不同的变量或表达式?
发布于 2019-11-14 13:39:32
这些作业中的变量由于展开的顺序而不受支持。
但是,您可以做的是为作业策略使用模板包含语法(https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops),并将代理名称作为参数传入。
因此,您在自己的YAML文件中的构建作业可能如下所示:
parameters:
agentName1: ''
agentName2: ''
agentName3: ''
jobs:
- job: RunOnEveryAgent
strategy:
maxParallel: 3
matrix:
agent_1:
agentName: ${{ parameters.agentName1 }}
agent_2:
agentName: ${{ parameters.agentName2 }}
agent_3:
agentName: ${{ parameters.agentName3 }}
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
- Agent.Name -equals ${{ parameters.agentName3 }}
steps:然后您的主azure-pipelines.yml更改为如下所示:
resources:
- repo: self
trigger: none
jobs:
- template: buildjob.yml
parameters:
agentName1: 'Hosted Agent'
agentName2: 'Hosted VS2017 2'
agentName3: 'Hosted VS2017 3'发布于 2020-11-26 10:10:07
parameters:
- name: agentNames
type: object
default: []
jobs:
- job: RunOnEveryAgent
strategy:
matrix:
${{ each agentName in parameters.agentNames }}:
${{ agentName }}:
agentName: ${{ agentName }}
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
- Agent.Name -equals $(agentName)如果将来要添加更多代理,这将是一个更好的解决方案。
https://stackoverflow.com/questions/53171662
复制相似问题