如何在 YAML 上实现这种设置:
我特别想知道
artifact
部分。我该如何实现它?我认为我应该做的是在阶段之前声明类型为 resources
和 pipelines
的 repositories
,然后在每个阶段下的每个作业上使用 DownloadPipelineArtifact@2
步骤。但在我看来,由于我们有很多阶段,我最终会多次重复代码。有什么办法可以实现这一点吗?
或者更确切地说,我是否创建一个单独的阶段来下载工件和存储库,以及它之后的阶段dependsOn它?
我就是不明白!
来自当前管道和关联管道资源的所有可用工件都会自动下载到部署作业中并可供您的部署使用。
但是,根据存储库资源,部署作业不会自动克隆源存储库。我们需要在您的工作中使用
checkout
明确定义源存储库
${{each}}
表达式,并插入 templates 来扩展 steps
、 jobs
或 stages
(如果适用)。这是一个示例供您参考。
mainPipeline.yml
trigger: none
pool:
vmImage: ubuntu-latest
parameters:
- name: environments
type: object
default:
- DEV
- QA
- PROD
resources:
repositories:
- repository: AnotherRepo # Not self
type: git
name: Repo1
pipelines:
- pipeline: UpstreamBuildPipeline
source: PipelinePublishingArtifacts
stages:
- ${{ each env in parameters.environments }}:
- template: stageTemplate.yml
parameters:
env: ${{env}}
- stage: Stage_Downstream
dependsOn:
- ${{ each env in parameters.environments }}:
- Stage_${{ env }}
jobs:
- job: Job_0
steps:
- checkout: none
- script: |
echo "This is a traditional job. When no checkout steps are defined,"
echo "The default behavior is as if checkout: self were the first step, and the current repository is checked out."
- job: Job_1
dependsOn: Job_0
steps:
- checkout: self
- checkout: AnotherRepo
- download: UpstreamBuildPipeline
stageTemplate.yml
parameters:
- name: env
default: ''
stages:
- stage: Stage_${{parameters.env}}
dependsOn: [] # The stage is independent from other stages
jobs:
- deployment: Deploy_${{parameters.env}}
environment: ${{parameters.env}}
strategy:
runOnce:
preDeploy:
steps:
- download: none
- script: |
echo "This is a deployment job. All available artifacts from the current pipeline and from the associated pipeline resources are automatically downloaded in deployment jobs and made available for your deployment."
echo "To prevent downloads, specify download: none."
echo "A deployment job doesn't automatically clone the source repo. You can checkout the source repo within your job with checkout: self."
deploy:
steps:
- checkout: self
- checkout: AnotherRepo
- script: |
tree $(System.DefaultWorkingDirectory)
displayName: Check repo resources
# - download: UpstreamBuildPipeline
- script: |
tree $(Pipeline.Workspace)
displayName: Check pipeilne resources