问题:如何在YAML管道中为以下上下文设置CI / CD。
分支
环境
最近的解决方案
build:创建项目工件 build.yml
trigger:
- master
- release/*
pool:
vmImage: 'ubuntu-latest'
steps:
- powershell: |
New-Item -Path . -Name "testfile1.txt" -ItemType "file" -Value "This is a text string."
- publish: $(Pipeline.workspace)
artifact: testArtifact
release-phase1:部署master分支以接受 release-phase1.yml
trigger: none
resources:
pipelines:
- pipeline: pipelineId
source: build
trigger:
branches:
- master
pool:
vmImage: 'ubuntu-latest'
jobs:
- deployment: DeployWeb
environment: 'testenvironment'
strategy:
runOnce:
deploy:
steps:
- script: echo FOO
release-phase2:部署release分支进行测试 release-phase2.yml
trigger: none
resources:
pipelines:
- pipeline: pipelineId
source: build
trigger:
branches:
- release/current
pool:
vmImage: 'ubuntu-latest'
jobs:
- deployment: DeployWeb
environment: 'testenvironment'
strategy:
runOnce:
deploy:
steps:
- script: echo FOO
release-phase3:将release-1分支部署到沙箱,并在手动批准后上线 release-phase3.yml
trigger: none
resources:
pipelines:
- pipeline: pipelineId
source: build
trigger:
branches:
- release/previous
pool:
vmImage: 'ubuntu-latest'
jobs:
- deployment: DeployWeb
environment: 'testenvironment'
strategy:
runOnce:
deploy:
steps:
- script: echo FOO
为什么此解决方案无法满足我们的需求:
追求目标
答案 0 :(得分:0)
由于您有多个分支(master和release分支),因此将构建不同的分支并将其部署到不同的环境。因此,您可以尝试在每个分支中使用CI构建yaml管道,并将CD部署yaml管道放在master分支中的template yaml中。(您必须在每个分支中都具有build yaml文件,才能在该分支中获取代码。内置的。您可以检查此thread)。
下面是一个简单的示例。
在主分支中
有azure-pipelines.yml和template-deploy.yml。在azure-pipelines.yml中,Environment
值将作为参数传递给template-deploy.yml。以便将构建版本部署到其相应的环境。
azure-pipelines.yml:
trigger:
- master
- release/*
pool:
vmImage: 'windows-latest'
resources:
repositories:
- repository: deploy
type: git
name: {project name}
jobs:
- job: Build
steps:
- script: echo "start build job"
- template: template-deploy.yml@deploy
parameters:
envir: "prod"
template-deploy.yml:
parameters:
envir: ""
jobs:
- deployment: DeployWeb
environment: '${{parameters.envir}}'
strategy:
runOnce:
deploy:
steps:
- script: echo FOO
在发行分支中
您可以定义其单独的ci build yaml,如下例所示:
release-phase2分支中的azure-pipelines.yml:
pool:
vmImage: 'windows-latest'
resources:
repositories:
- repository: deploy
type: git
name: {project name}
jobs:
- job: Build
steps:
- script: echo "start build job"
- template: template-deploy.yml@deploy
parameters:
envir: "test"