azure-devops - Optional job templates in YAML Pipelines
问题描述
Is it possible to optionally include templates based on some kind of template expression? Specifically, I want my top-level definition in azure-pipelines.yml to call out which build job templates to use in an included stage template:
azure-pipelines.yml :
stages:
- template: generic-build-stage.yml # Template reference
parameters:
# Example of optional build templates to use
buildTypes: [SpecificBuildJobs1, SpecificBuildJobs3, SpecificBuildJobs4]
generic-build-stage.yml :
parameters:
buildTypes: ???
stages:
- stage: generic_build
jobs:
${{ }} # ???? What goes here to include the appropriate templates
- template: ???
The template expression above would ideally expand to this:
jobs:
- template: specific-build-jobs1.yml
- template: specific-build-jobs3.yml
- template: specific-build-jobs4.yml
Edit: The "Iterative insertion" example in the docs seems to suggest that some form of dynamic, parse-time insertion is possible.
解决方案
It seems to be impossible, for the template reference is resolved at parse time.
You may have to set multiple templates for main pipeline, and set the value for buildTypes
as the specific template name for job templates, and in generic-build-stage.yml
use - template:${{parameters.buildTypes}}.yml
to call corresponding job template;
Azure-pipelines.yml:
stages:
- template: generic-build-stage.yml
parameters:
buildTypes:specific-build-jobs1
- template: generic-build-stage.yml
parameters:
buildTypes:specific-build-jobs3
generic-build-stage.yml
parameters:
buildTypes: ""
stages:
- stage: generic_build
jobs:
- template: ${{parameters.buildTypes}}.yml
推荐阅读
- c# - 来自另一个域的 Cookie 出现在我们域的 Cookie 中。我需要帮助使用 C# 删除该 cookie
- python - 如何在 Python 上使用 app_store_scraper 克服请求限制?
- react-native - 如何在 createMaterialBottomTabNavigator 中的点击时删除 TabBarIcon 的背景颜色(当触摸处于活动状态时)在 react native 和 react native 纸上
- angular - 将 Angular 文件部署到 Azure StorageAccount - 无法加载资源:
- r - 如何从数据框列中提取电子邮件 ID 并使用 R 自动发送邮件
- python - 通过运行 python 文件绘制 matplotlib
- c - 类型双关是函数指针未定义的行为吗?
- angular5 - 未设置猫头鹰日期时间值
- node.js - 如何在 DynamoDB 的 UpdateExpression 中将额外属性设置为 null?
- c# - 无法在 ASP.NET 5.0 中设置 cookie