Azure DevOps: CI/CD IaC with YAML Pipeline

Sign in to your organisation (https://dev.azure.com/{yourorganization})

Azure DevOps looks like the following screenshot.

Find more details about key consepts in Azure Pipelines Key Concepts

Find more details about extending Azure Pipelines Templates in Azure Pipelines Templates

Find more details about Azure template parameters in Azure Pipeline Template Parameters

Find more details about Azure template predefined variables in Azure Pipeline Template Predefined Variables

Find more details about Azure template script variables in Azure Pipeline Template Script Variables

Find more details about usage of expressions in Azure Pipelines Expressions

In a pipeline, template expression variables (${{ variables.var }}) get processed at compile time, before runtime starts. Macro syntax variables ($(var)) get processed during runtime before a task runs. Runtime expressions ($[variables.var]) also get processed during runtime but are intended to be used with conditionsand expressions

Find more details about usage of Azure template variables in Azure Pipeline Template Variable Usage

Azure DevOps Organizations Page

Azure DevOps Selected Organization Page

Azure DevOps Pipelines in Project Page

Find all the pipelines in https://github.com/kenanhancer/azure-devops-ci-cd-demo GitHub repository.

Demo 1

stages:
  - stage: Stage_A
    jobs:
    - job: MyJob
      steps:
      - checkout: none
      
      - script: echo My first job
  
  - stage: Stage_B
    jobs:
    - job: MyJob2
      steps:
      - checkout: none

      - script: echo My Second job

Find all runs in Azure DevOps

After clicking any stage or job, we will see the following screenshot.

Demo 2

stages:
  - stage: Stage_A
    jobs:
    - job: MyJob
      steps:
      - checkout: none
      
      - script: echo My first job
  
  - stage: Stage_B
    dependsOn: Stage_A
    jobs:
    - job: MyJob2
      steps:
      - checkout: none

      - script: echo My Second job

  - stage: Stage_C
    dependsOn: Stage_B
    jobs:
    - job: MyJob3
      steps:
      - checkout: none

      - script: echo My Third job

      - script: echo My Fourth job

      - script: echo My Fifth job

Find all runs in Azure DevOps

Demo 3

jobs:
  - job: MyJob
    steps:
    - checkout: none
    
    - script: echo My first job

Find all runs in Azure DevOps

Demo 4

steps:
- checkout: none

- script: echo My first job

Find all runs in Azure DevOps

Demo 5

stages:
  - stage: Build
    jobs:
    - job: BuildJob
      steps:
      - checkout: none

      - script: echo Building!

  - stage: Test
    jobs:
    - job: TestOnWindows
      steps:
      - checkout: none

      - script: echo Testing on Windows!

    - job: TestOnLinux
      steps:
      - checkout: none

      - script: echo Testing on Linux!

  - stage: Deploy
    jobs:
    - job: Deploy
      steps:
      - checkout: none
      
      - script: echo Deploying the code!

Find all runs in Azure DevOps

Demo 6

stages:
  - stage: BuildWin
    displayName: Build for Windows
    jobs:
      - job: Build
        steps:
        - checkout: none

        - script: echo Building in Windows!

  - stage: BuildLinux
    displayName: Build for Linux
    dependsOn: [] # by specifying an empty array, this stage doesn't depend on the stage before it
    jobs:
      - job: Build
        steps:
        - checkout: none

        - script: echo Building in Linux!

  - stage: TestOnWindows
    dependsOn: BuildWin
    jobs:
    - job: TestOnWindows
      steps:
      - checkout: none

      - script: echo Testing on Windows!

  - stage: TestOnLinux
    dependsOn: BuildLinux
    jobs:
    - job: TestOnLinux
      steps:
      - checkout: none

      - script: echo Testing on Linux!

  - stage: DeployWindows
    dependsOn: TestOnWindows
    jobs:
    - job: Deploy
      steps:
      - checkout: none

      - script: echo Deploying the code to Windows!

  - stage: DeployLinux
    dependsOn: TestOnLinux
    jobs:
    - job: Deploy
      steps:
      - checkout: none
      
      - script: echo Deploying the code to Linux!

Find all runs in Azure DevOps

Demo 7

trigger:
  - master
  
pool: 
  vmImage: ubuntu-latest

jobs:
- job: PreWork
  steps:
  - checkout: none

  - script: echo "Do pre-work"

- job: PostWork
  steps:
  - checkout: none

  - script: echo "Do post-work using a different hosted image"

Find all runs in Azure DevOps

Leave a Reply