首页 > 解决方案 > 如何从 azure 管道中选择特定的构建代理来运行您的构建?

问题描述

因此,我试图想出一种方法来允许在构建管道中轻松选择给定代理,仅用于调试目的。到目前为止,我有以下片段。两者都可以在没有 if 片段的情况下工作,但是我试图根据设置的参数或设置的变量来执行其中一个或另一个,这样如果它处于调试模式,它将选择和代理,如果不是,那么它只会使用池来选择一个代理来运行构建。到目前为止,虽然没有运气。

variables:
  debugMode: 'false'

parameters:
- name: poolOption
  type: string
  default: 'ZupaDeploymentPool'
- name: debugMode
  type: string
  default: 'true'
- name: debugMachine
  type: string
  default: 'ZUPBUILD03'

trigger:
  batch: true
  branches:
    include:
    - master
  paths:
    exclude:
    - README.md

${{ if ne($(debugMode), 'false') }}:
  pool: ${{ parameters.poolOption }} 

${{ if ne($(debugMode), 'true') }}:
  pool:
    name: ${{ parameters.poolOption }}
    demands: 
    - Agent.Name -equals ${{ parameters.debugMachine }}

标签: azuredeploymentyamlazure-pipelines

解决方案


因此,在与上面的 kevin-lu-msft 进行快速聊天后,我将使用此解决方案来处理在池中选择特定代理。

parameters:
- name: debugMachine
  displayName: 'Run on selected agent:'
  type: string
  default: 'Auto Select From Pool'
  values:
  - 'Auto Select From Pool'
  - 'MACHINE01'
  - 'MACHINE02'
  - 'MACHINE03'
  - 'MACHINE04'
  - 'MACHINE05'

jobs:
-job: build

  # -----------------------------------------------------------------------------------------------
  # This is the pool selection section if a specific debug machine is passed in via the params 
  # It will select that specific one to run the build on. unfortunately azure doesnt let you pass 
  # vars or params to the process string in the demands which would have made this alot cleaner.
  pool:
    name: 'YOUAGENTSPOOLNAME'
    ${{ if ne(parameters.debugMachine, 'Auto Select From Pool') }}:
      ${{ if eq(parameters.debugMachine, 'MACHINE01') }}:
        demands:
        - Agent.Name -equals MACHINE01
      ${{ if eq(parameters.debugMachine, 'MACHINE02') }}:
        demands:
        - Agent.Name -equals MACHINE02
      ${{ if eq(parameters.debugMachine, 'MACHINE03') }}:
        demands:
        - Agent.Name -equals MACHINE03
      ${{ if eq(parameters.debugMachine, 'MACHINE04') }}:
        demands:
        - Agent.Name -equals MACHINE04
      ${{ if eq(parameters.debugMachine, 'MACHINE05') }}:
        demands:
        - Agent.Name -equals MACHINE05

  steps:
    - script: "echo finally it works"

推荐阅读