Author : MD TAREQ HASSAN

CD YAML pipeline

Prerequisites

Prject setup

azure-pipelines-cd.yml

trigger: none # Since CI completion trigger will be used

pool:
  vmImage: ubuntu-latest

resources:
  pipelines:
  - pipeline: XyzapiPipelineCI
    source: 'XyzAPI-Pipeline-CI'
    trigger:
      branches:
        include:
        - master

jobs:
# add script job here temporarily for testing

Create pipeline from existing azure-pipelines-cd.yml

Azure DevOps - Create CD pipeline from existing YAML file Step 1

Azure DevOps - Create CD pipeline from existing YAML file Step 2

Azure DevOps - Create CD pipeline from existing YAML file Step 3

Azure DevOps - Create CD pipeline from existing YAML file Step 4

Azure DevOps - Create CD pipeline from existing YAML file Step 5

Azure DevOps - Create CD pipeline from existing YAML file Step 6

Azure DevOps - Create CD pipeline from existing YAML file Step 7

Azure DevOps - Create CD pipeline from existing YAML file Step 8

Azure DevOps - Create CD pipeline from existing YAML file Step 9

Test pipeline completion trigger

A test run of CI pipeline to see if CD pipeline gets triggered after completion of CI pipeline

Azure DevOps - Test pipeline completion trigger Step 1

Azure DevOps - Test pipeline completion trigger Step 2

Azure DevOps - Test pipeline completion trigger Step 3

Azure DevOps - Test pipeline completion trigger Step 4

Azure DevOps - Test pipeline completion trigger Step 5

To deploy to ASK environment, see next section

Deploy to AKS environment

‘AcrPull’ role to kubelet managed identity

AcrPull role to kubelet managed identity

Variable group

Variable group will be linked to pipeline as following

# ... ... ...

variables:
- group: 'xyz-api-vg'

# ... ... ...

Variable group for CD YAML pipeline

Pipeline variables

Pipeline variables for CD YAML pipeline

Deployment job to deploy K8s manifest file to AKS

azure-pipelines-cd.yml

trigger: none # Since CI completion trigger will be used

pool:
  vmImage: ubuntu-latest

resources:
  pipelines:
  - pipeline: XyzapiPipelineCI
    source: 'XyzAPI-Pipeline-CI'
    trigger:
      branches:
        include:
        - master

variables:
- group: 'xyz-api-vg'

jobs:
      
- deployment: deployToAKS
  displayName: Deploy to AKS
  dependsOn: buildAndPushDockerImageJob
  environment: 'AKSDemoEnvironment.devops-demo'
  strategy:
    runOnce:
     deploy:
       steps:
        - powershell: |
           '# service
           apiVersion: v1
           kind: Service
           metadata:
             name: $(appName)
             namespace: $(targetNamespace)
             labels:
               app: $(appName)
           spec:
             type: ClusterIP
             ports:
               - port: 80
                 targetPort: http
                 protocol: TCP
                 name: http
             selector:
               app: $(appName)
           
           ---
           
           # deployment
           apiVersion: apps/v1
           kind: Deployment
           metadata:
             name: $(appName)
             namespace: $(targetNamespace)
             labels:
               app: $(appName)
           spec:
             replicas: 3
             selector:
               matchLabels:
                 app: $(appName)
             template:
               metadata:
                 labels:
                   app: $(appName)
               spec:
                 containers:
                   - name: $(appName)
                     image: $(acrName).azurecr.io/$(repositoryName):$(Build.BuildId)
                     ports:
                       - name: http
                         containerPort: 80
                         protocol: TCP
                     env:
                     - name: API_BASE_URI
                       value: $(apiBaseUri)
           
           ---
           
           # ingress
           apiVersion: networking.k8s.io/v1
           kind: Ingress
           metadata:
             name: $(appName)
             namespace: $(targetNamespace)
             annotations:
               kubernetes.io/ingress.class: azure/application-gateway
               appgw.ingress.kubernetes.io/backend-path-prefix: "/api/$(apiBaseUri)/"
           spec:
             rules:
             - host: $(appGwDnsUrl)
               http:
                 paths:
                 - path: /api/$(apiBaseUri)/*
                   pathType: Prefix
                   backend:
                     service:
                       name: $(appName)
                       port:
                         number: 80' | Set-Content $(Agent.TempDirectory)/manifest.yaml
          displayName: 'Generate K8s Manifest file'

        - task: KubernetesManifest@0
          displayName: 'Deploy K8s Manifest to AKS'
          inputs:
             action: deploy
             manifests: '$(Agent.TempDirectory)/manifest.yaml'

Release pipeline using classic editor

Setting target artifact to Release Pipeline

Azure DevOps - Release pipeline using classic editor Step 1

Azure DevOps - Release pipeline using classic editor Step 2

Azure DevOps - Release pipeline using classic editor Step 3

Azure DevOps - Release pipeline using classic editor Step 4

Azure DevOps - Release pipeline using classic editor Step 5

Azure DevOps - Release pipeline using classic editor Step 6

Azure DevOps - Release pipeline using classic editor Step 7

Azure DevOps - Release pipeline using classic editor Step 8

Azure DevOps - Release pipeline using classic editor Step 9

Azure DevOps - Release pipeline using classic editor Step 10

Azure DevOps - Release pipeline using classic editor Step 11

Deployment conditions in classic release pipeline

Pre-deployment conditions

Azure DevOps - Release pipeline Pre-deployment conditions

Pre-deployment approver

Azure DevOps - Pre deployment condition set approver

Post-deployment conditions

Azure DevOps - Release pipeline Post-deployment conditions

Post-deployment approver

Azure DevOps - Post deployment condition set approver

Delete classic release pipeline

Azure DevOps - deleting release pipeline

Classic release pipeline trigger

Azure DevOps - Release pipeline (Continous deployment) trigger

Cloning stage in classic release pipeline

Azure DevOps - Cloning release pipeline stage Step 1

Azure DevOps - Cloning release pipeline stage Step 2

Azure DevOps - Cloning release pipeline stage Step 3

Azure DevOps - Cloning release pipeline stage Step 4

Multiple stages in classic release pipeline

Azure DevOps - Release pipeline multiple stages

Release manually in classic release pipeline

Azure DevOps - CD pipeline release manually Step 1

Azure DevOps - CD pipeline release manually Step 2

Azure DevOps - CD pipeline release manually Step 3