Jam*_*fer 1 azure-devops azure-pipelines
我有一个用 YAML 编写的 Azure Pipeline,只要对分支进行更改,它就会从 CI 触发器运行master。它还可以从拉取请求或由用户针对任何分支手动触发。
由于使用了许多许可组件,因此构建master需要在特定代理上运行。其他版本则不然,事实上我宁愿它们在其他代理上运行。
所以我的问题是,有没有办法根据触发构建的内容或构建正在构建的分支来在 YAML 管道中指定不同的代理/池?我希望这是在管道中永久配置的行为,而不是要求用户在他们希望在其他地方构建的每个分支上更新 YAML。
我在有关池/需求/条件关键字的文档部分中看不到任何明显的内容。
我通过将steps作业放入模板中解决了这个问题,然后在管道中使用不同的condition条目创建一组作业,以便我们可以demands根据这些条件进行设置。
骨架版本如下所示:
- stage: Build
jobs:
- job: TopicBranchAndPullRequestBuild
condition: or(startsWith(variables['Build.SourceBranch'], 'refs/heads/topic'), startsWith(variables['Build.SourceBranch'], 'refs/pull'))
displayName: 'Build topic Branch or Pull Request'
pool:
name: the-one-and-only-pool
demands:
- HasLicensedComponents -equals false
steps:
- template: build-template.yml
- job: MasterAndReleaseBranchBuild
condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release'))
displayName: 'Build master or release Branch'
pool:
name: the-one-and-only-pool
demands:
- HasLicensedComponents -equals true
steps:
- template: build-template.yml
Run Code Online (Sandbox Code Playgroud)
显然,此处给出的值仅作为示例,但除此之外,这就是我正在工作的内容。
| 归档时间: |
|
| 查看次数: |
5974 次 |
| 最近记录: |