Fis*_*man 4 ios azure-devops azure-pipelines
我们正在使用 Azure DevOps 进行 iOS 应用程序的 CI/CD。我们提供了带有 VM 的 Mac 计算机,并且 Azure DevOps 代理安装在这些 VM 上。
有时我们的管道会由于代理虚拟机不稳定而失败。如何在管道中提供一个选项来在池中的特定代理上运行作业?在 Jenkins 和 TeamCity 中都可以轻松实现这一目标。然而,这里我们使用 YAML 定义管道,这似乎更棘手。
带有机器列表的参数以及管道中的功能条件和代理中定义的功能是否可行?
但请记住:1.我很乐意在单击“运行作业”时选择它,2.可用代理列表应该可以作为下拉菜单3.默认情况下,它应该使用池中的随机代理
为了在YAML文件中实现这一点,我们可以定义两个运行时参数,其中一个参数用于从下拉列表中选择指定代理,一个参数用于决定是使用特定代理还是默认随机代理。
换句话说,我们需要使用一个参数来选择需求,并使用另一个参数来禁用/启用先前的需求。如果我们禁用之前的需求,Azure DevOps 将默认使用随机代理。
我设置了以下示例 YAML 文件:
parameters:
- name: IfNeedDemands
type: boolean
default: False
- name: AgentSelect
displayName: Agent Select
type: string
values:
- VsAgent1
- VsAgent2
- VsAgent3
- VsAgent4
trigger: none
jobs:
- job: build
displayName: build
pool:
name: MyPrivateAgent
${{ if eq(parameters.IfNeedDemands, true) }}:
demands: Agent.Name -equals ${{ parameters.AgentSelect }}
steps:
- script: echo The value is ${{ parameters.AgentSelect }}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,参数IfNeedDemands和语法${{ if eq(parameters.IfNeedDemands, true) }}:用于确定是否启用需求。
AgentSelect然后是用于选择私人代理的参数。
我测试了一下,效果符合我的预期,您可以检查一下是否满足您的需求。
| 归档时间: |
|
| 查看次数: |
5881 次 |
| 最近记录: |