我有以下场景,使用 YAML 管道:
我尝试了多种方法,但似乎没有任何效果。
是否有推荐的方法来强制依赖作业在同一个代理中运行?
注意:我不需要将它们绑定到特定代理,而是绑定到同一个代理。我实际上希望使用所有代理,但阶段中的作业必须在单个代理中运行。其他阶段或其他管道运行可以在其他代理中运行。
提供更多关于为什么我需要使用代理池中的单个代理的背景信息:
使用每个构建代理独有的功能非常重要,例如
Agent.Name
:
第一个作业将设置一个具有该值的输出变量:
echo "##vso[task.setvariable variable=CurrentAgent;isOutput=true]$(Agent.Name)"
剩余的工作将使用基于该变量的需求:
pool:
name: MyAgentPool
demands: Agent.Name -equals $(CurrentAgent)
trigger: none
stages:
- stage: A
jobs:
- job: jobA0
displayName: A0
pool:
name: Default
steps:
- checkout: none
- script: |
echo "Running job using agent $(Agent.Name)"
echo "##vso[task.setvariable variable=CurrentAgent;isOutput=true]$(Agent.Name)"
name: setAgent
displayName: 'Set current agent'
- job: jobA1
displayName: A1
dependsOn: jobA0
variables:
CurrentAgent: $[ dependencies.jobA0.outputs['setAgent.CurrentAgent'] ]
pool:
name: Default
demands: Agent.Name -equals $(CurrentAgent)
steps:
- checkout: none
- script: |
echo "Running job using agent $(Agent.Name)"
displayName: 'Display current agent'
- job: jobA2
displayName: A2
dependsOn:
- jobA0 # add the dependency on the job that sets the variable
- jobA1
variables:
CurrentAgent: $[ dependencies.jobA0.outputs['setAgent.CurrentAgent'] ]
pool:
name: Default
demands: Agent.Name -equals $(CurrentAgent)
steps:
- checkout: none
- script: |
echo "Running job using agent $(Agent.Name)"
displayName: 'Display current agent'
- job: jobA3
displayName: A3
dependsOn:
- jobA0 # add the dependency on the job that sets the variable
- jobA2
variables:
CurrentAgent: $[ dependencies.jobA0.outputs['setAgent.CurrentAgent'] ]
pool:
name: Default
demands: Agent.Name -equals $(CurrentAgent)
steps:
- checkout: none
- script: |
echo "Running job using agent $(Agent.Name)"
displayName: 'Display current agent'