您可以为资源制作模板并将其与 YAML 管道中的步骤结合起来吗?
Can you make templates for resources and combine it with steps in a YAML pipeline?
我有一个管道,其中有一个类似这样的部分列出了将触发管道的管道。
resources:
# List all the microservice pipelines to be watched plus infrastructure, the pipeline name is the name
# of the stack. Note template-maven and template-gradle are not to be part of this build.
pipelines:
- pipeline: auth
project: services
source: auth
branch: master
trigger:
branches:
include:
- master
- pipeline: ai
project: services
source: artificial-intelligence
branch: master
trigger:
branches:
include:
- master
- pipeline: ui
project: frontend
source: ui CI
branch: master
trigger:
branches:
include:
- master
然后我完成了以下步骤的工作(因为 deployment
提取所有文件,我只需要每个管道中的一个文件夹
- job: publishDeploymentPipelineFiles
condition: not(canceled())
steps:
- checkout: none
- download: auth
artifact: drop
- download: ai
artifact: drop
- download: ui
artifact: drop
我希望的是某种形式的模板
steps:
- checkout: none
- template: pull-deployment-manifests.yml
parameters:
sources:
- project: services
source: auth
stackName: auth
- project: services
source: artificial-intelligence
stackName: ai
- project: frontend
source: ui CI
stackName: ui
仅列出项目和 CI 管道并从 stackName
创建适当的管道 ID,并创建资源和步骤。
我现在的解决方法是创建一个项目,该项目采用包含这些项目的 CSV 并生成 azure-pipelines.yml
据我所知,您不能动态创建资源。所以你创造了这个
steps:
- checkout: none
- template: pull-deployment-manifests.yml
parameters:
sources:
- project: services
source: auth
stackName: auth
- project: services
source: artificial-intelligence
stackName: ai
- project: frontend
source: ui CI
stackName: ui
和 运行 在模板内签出,除非您在根级别定义了具有这些名称的资源。
如文档所述here:
Resources are defined at one place and can be consumed anywhere in your pipeline.
当然可以设置一个带有资源的模板,然后在 YAML 管道中使用这个模板。您可以参考“Extend from a template with resources”。
但是请注意,如果您在模板中定义了资源和步骤,则无法在 YAML 管道中的 steps
键下使用它。您应该使用 extends
键从模板扩展资源,就像文档中的示例一样。
您可能需要在模板中定义所有必需的步骤,或将其他 step template
中的步骤用于模板。
我有一个管道,其中有一个类似这样的部分列出了将触发管道的管道。
resources:
# List all the microservice pipelines to be watched plus infrastructure, the pipeline name is the name
# of the stack. Note template-maven and template-gradle are not to be part of this build.
pipelines:
- pipeline: auth
project: services
source: auth
branch: master
trigger:
branches:
include:
- master
- pipeline: ai
project: services
source: artificial-intelligence
branch: master
trigger:
branches:
include:
- master
- pipeline: ui
project: frontend
source: ui CI
branch: master
trigger:
branches:
include:
- master
然后我完成了以下步骤的工作(因为 deployment
提取所有文件,我只需要每个管道中的一个文件夹
- job: publishDeploymentPipelineFiles
condition: not(canceled())
steps:
- checkout: none
- download: auth
artifact: drop
- download: ai
artifact: drop
- download: ui
artifact: drop
我希望的是某种形式的模板
steps:
- checkout: none
- template: pull-deployment-manifests.yml
parameters:
sources:
- project: services
source: auth
stackName: auth
- project: services
source: artificial-intelligence
stackName: ai
- project: frontend
source: ui CI
stackName: ui
仅列出项目和 CI 管道并从 stackName
创建适当的管道 ID,并创建资源和步骤。
我现在的解决方法是创建一个项目,该项目采用包含这些项目的 CSV 并生成 azure-pipelines.yml
据我所知,您不能动态创建资源。所以你创造了这个
steps:
- checkout: none
- template: pull-deployment-manifests.yml
parameters:
sources:
- project: services
source: auth
stackName: auth
- project: services
source: artificial-intelligence
stackName: ai
- project: frontend
source: ui CI
stackName: ui
和 运行 在模板内签出,除非您在根级别定义了具有这些名称的资源。
如文档所述here:
Resources are defined at one place and can be consumed anywhere in your pipeline.
当然可以设置一个带有资源的模板,然后在 YAML 管道中使用这个模板。您可以参考“Extend from a template with resources”。
但是请注意,如果您在模板中定义了资源和步骤,则无法在 YAML 管道中的 steps
键下使用它。您应该使用 extends
键从模板扩展资源,就像文档中的示例一样。
您可能需要在模板中定义所有必需的步骤,或将其他 step template
中的步骤用于模板。