如何从azure管道中选择特定的构建代理以在其上运行构建? [英] How to select a specific build agent from azure pipelines to run your build on?
问题描述
因此,我试图想出一种方法来允许仅出于调试目的而在构建管道中轻松选择给定的代理.到目前为止,我有以下片段.两者都没有if片段缠结的情况,但是我试图根据设置的参数或设置的反变量来做一个或另一个,以便如果它处于调试模式,它将选择并代理,如果不是,则它将使用池选择要对其运行构建的代理.到目前为止,没有运气.
So im trying to come up with a way to allow an easy selection of a given agent within the build pipeline just for debugging purposes. So far I have the below snippet. both work without the if snippets wrapped around but I was trying to do one or the other based on either params being set or inturn variables being set so that if it was in debug mode it would select and agent and if it wasnt then it would just use the pool to select an agent to run the builds against. So far no luck though.
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 }}
推荐答案
我测试了您的YAML示例并进行了一些修改.您可以尝试将表达式"设置为一个阶段,然后检查其是否可以按预期工作.
I tested your YAML sample and made some modifications. You could try to set the "Expressions" under a stage and check if it could work as expected.
这里是一个示例,您可以参考它.
Here is an example, you could refer to it.
trigger:
- master
parameters:
- name: poolOption
type: string
default: 'Windows-latest'
- name: debugMode
type: string
default: false
values:
- true
- false
- name: debugMachine
type: string
default: 'ubuntu-16.04'
stages:
- stage: A
jobs:
- job: testjob
pool:
${{ if eq(parameters.debugmode, 'true') }}:
vmImage: ${{ parameters.poolOption }}
${{ if eq(parameters.debugmode, 'false') }}:
vmImage: ${{ parameters.debugMachine }}
steps:
- script : "echo Hello, world!"
注意:我使用的是Microsoft托管的代理,因此我使用的是 vmImage
字段.
Note: I am using Microsoft-hosted agents, so I am using the vmImage
field.
您可以根据您的需要指定特定的自托管代理( name
字段).
希望这会有所帮助.
这篇关于如何从azure管道中选择特定的构建代理以在其上运行构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!