Azure devops 基于条件参数在池上执行Azure Devops作业

Azure devops 基于条件参数在池上执行Azure Devops作业,azure-devops,azure-pipelines,azure-pipelines-yaml,Azure Devops,Azure Pipelines,Azure Pipelines Yaml,我正在尝试根据条件在特定池上执行Azure Devops作业。 目标是在自托管代理和microsoft代理之间切换。 以下是配置: 参数: 自定义代理:true 工作: -工作:测试 显示名称:测试作业 -${{if eq(parameters.custom_agent,true)}}: -游泳池: 姓名:mypool 要求: -agent.os-等于Linux -${{if eq(parameters.custom_agent,false)}: -游泳池: vmImage:“ubuntu最新版

我正在尝试根据条件在特定池上执行Azure Devops作业。 目标是在自托管代理和microsoft代理之间切换。 以下是配置:

参数:
自定义代理:true
工作:
-工作:测试
显示名称:测试作业
-${{if eq(parameters.custom_agent,true)}}:
-游泳池:
姓名:mypool
要求:
-agent.os-等于Linux
-${{if eq(parameters.custom_agent,false)}:
-游泳池:
vmImage:“ubuntu最新版本”
步骤:
-任务:npmAuthenticate@0


有什么想法吗?

看起来池不是一个有效的属性

尝试将您的工作切换到:

工作:


我们可以指定运行步骤、作业或阶段的条件。我们可以使用不同的条件条目配置管道中的作业,并根据这些条件设置需求

骨架版本如下所示:

parameters:
- name: custom_agent
  displayName: Pool Image
  type: boolean
  default: True

jobs:
  - job: selfhostedagent
    condition: eq(${{ parameters.custom_agent }}, True)
    displayName: 'self_hosted agent'
    pool:
      name: Default
      demands:
        - Agent.Name -equals WS-VITOL-01
    steps:
      - script: echo self_hosted agent

  - job: hostedagent
    condition: eq(${{ parameters.custom_agent }}, False)
    displayName: 'hosted agent'
    pool:
      vmImage: 'ubuntu-latest'
      
    steps:
      - script: echo hosted agent
更新1

此外,我们可以配置任务模板,然后在步骤中使用该模板

结果:


如果您使用非vm池,另一种有条件选择池的方法:

变量:
-${{if eq(parameters.custom_agent,true)}}:
-名称:testJobPool
值:mypool
-${{if eq(parameters.custom_agent,false)}:
-名称:testJobPool
值:mypool_秒
工作:
-工作:测试
显示名称:测试作业
游泳池:
名称:$(testJobPool)
步骤:
-任务:npmAuthenticate@0

这已经证明有效。

您好,这个问题有更新吗?如果答案能给你一些帮助,我们可以作为答案。在这种情况下,其他人可以直接找到有用的解决方案。如果没有,请随时在这里分享你的问题。好的,谢谢:)我没有测试这个,但我想你已经测试过了,它可以工作了。但我不喜欢使用部署进行测试的想法。看起来很奇怪!?没有?我没有测试过你的特定YAML。部署作业类型是YAML Pipleline的交付方面。因此,即使是测试站点部署,也只是将代码/基础设施部署到给定环境的术语<代码>池:在
-${{如果eq(parameters.custom_agent,true)}之后:
无效。
parameters:
- name: custom_agent
  displayName: Pool Image
  type: boolean
  default: True

jobs:
  - job: selfhostedagent
    condition: eq(${{ parameters.custom_agent }}, True)
    displayName: 'self_hosted agent'
    pool:
      name: Default
      demands:
        - Agent.Name -equals WS-VITOL-01
    steps:
      - script: echo self_hosted agent

  - job: hostedagent
    condition: eq(${{ parameters.custom_agent }}, False)
    displayName: 'hosted agent'
    pool:
      vmImage: 'ubuntu-latest'
      
    steps:
      - script: echo hosted agent