ios - 如何从 Azure DevOPS 中的池在特定代理上运行管道

标签 ios azure-devops azure-pipelines

我们将 Azure DevOps 用于 iOS 应用程序的 CI/CD。我们提供了带有 VM 的 mac 机器,Azure DevOps 代理安装在这些 VM 上。

有时我们的管道会因代理 VM 不稳定而失败。如何在管道中提供选项以在池中的特定代理上运行作业?这在 Jenkins 和 TeamCity 中都很容易实现。然而,在这里我们使用 YAML 定义管道,这似乎更棘手。

带有机器列表的参数以及管道中的能力条件和代理中定义的能力是否可行?

最佳答案

but keep in mind that: 1. I'd love to choose it while clicking "Run job", 2. List of available agents should be possible as a dropdown menu 3. By default it should use a random agent from pool

为了在 YAML 文件中实现这一点,我们可以定义两个 Runtime parameters ,其中一个参数用于从下拉列表中选择指定代理,一个用于决定是使用特定代理还是默认使用随机代理。

换句话说,我们需要使用一个参数来选择需求,并使用另一个参数来禁用/启用先前的需求。如果我们禁用之前的需求,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 }}

在上面的示例中,参数 IfNeedDemands 语法为 ${{ if eq(parameters.IfNeedDemands, true) }}: 用于确定是否启用 要求

然后参数AgentSelect用于选择私有(private)代理。

enter image description here

我测试了它是否符合我的预期,你可以检查它是否满足你的需求。

关于ios - 如何从 Azure DevOPS 中的池在特定代理上运行管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63298778/

相关文章:

iOS - 推送通知在辞职的 IPA 中不起作用

.net - 在云中混淆应用程序设置文件,但允许本地应用程序开发

rest - 如何使用 Azure DevOps REST API 创建新的构建管道?

git - 使用 VSTS API 在 VSTS 中的持续集成/持续交付过程中将文件提交到 Git

javascript - npm run prettier --检查与 azure pipeline 任务中的不同

azure - 如何在 Azure DevOps 中的 2 个构建管道之间创建依赖关系并将工作项链接到构建管道?

ios - 相机 View 未显示

ios - 需要使用 CallKit 在 iOS 10 中调用详细信息

objective-c - iPhone的简单动画

Azure Artifacts 在尝试构建 Dockerfile 时给出未经授权的信息