0
votes

Question: how do you setup CI/CD in YAML pipelines for following context.

branches

  • master
  • release/{ALPHABETICAL NAME} ex. release/Albert next release is release/Bertrand and so on.

environments

  • accept: everything that's pushed on master
  • test: latest release ex. release/Bertrand
  • sandbox: latest release -1 (here we can test hotfixes) ex. release/Albert
  • live: latest release -1 (with hotfixes)

Closest solution

build: creates project artifacts 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: deploys master branch to accept 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: deploys release branch to test 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: deploys release-1 branch to sandbox and after manual approval to live 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

Reasons why this solutions doesn't fulfill our needs:

  • the names of the release branches aren't static.
  • we should be able to run release-phase3.yml pipeline without running a build on this branch firts. It should download artifacts from the latest build of that branch. Which is not the case.

SHORT ON PURPOSE

1
Hi Did you check out below answer, how did it go? Please let me if there is any question.Levi Lu-MSFT

1 Answers

0
votes

Since you have multiple branches (master and releases branches), different branch is built and deploy to different environment. So you can try having the CI build yaml pipeline in each branch and put the CD deployment yaml pipeline in a template yaml in master branch.(You have to have the build yaml file in each branch to get the code in this branch built. You can check this thread).

Below is a simple example.

In master branch

There are azure-pipelines.yml and a template-deploy.yml. In azure-pipelines.yml the Environment value will be passed as a parameter to template-deploy.yml. So that the build will be deployed to its corresponding environment.

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

In the release branches

You can define its individual ci build yaml like below example:

azure-pipelines.yml in release-phase2 branch:

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"