← All Posts
Azure DevOps2 Aug 2024·11 min read

Azure Pipelines YAML: Build Your First CI/CD Pipeline

SR

Srinivas Rao

Cloud Architect & Lead Trainer, CloudTechTrainings

#Azure DevOps#CI/CD#YAML Pipelines#AZ-400#DevOps

YAML pipelines in Azure DevOps give you code-as-configuration for your entire CI/CD process. Unlike classic pipelines, YAML pipelines live in your Git repository — version-controlled, reviewable, and portable across projects.

Pipeline Structure Basics

An Azure Pipelines YAML file has a hierarchy: trigger → stages → jobs → steps. Here's a minimal pipeline that builds a Node.js application:

yaml
trigger:
  branches:
    include:
      - main
      - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  nodeVersion: '20.x'

stages:
  - stage: Build
    displayName: 'Build & Test'
    jobs:
      - job: BuildJob
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: $(nodeVersion)
            displayName: 'Install Node.js'

          - script: npm ci
            displayName: 'Install dependencies'

          - script: npm test
            displayName: 'Run tests'

          - task: PublishTestResults@2
            inputs:
              testResultsFiles: '**/test-results.xml'

          - task: ArchiveFiles@2
            inputs:
              rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
              archiveFile: '$(Build.ArtifactStagingDirectory)/app.zip'

          - task: PublishPipelineArtifact@1
            inputs:
              artifactName: 'drop'
              targetPath: '$(Build.ArtifactStagingDirectory)'

Adding a Deploy Stage

yaml
  - stage: Deploy
    displayName: 'Deploy to Azure'
    dependsOn: Build
    condition: succeeded()
    jobs:
      - deployment: DeployWeb
        environment: 'production'
        strategy:
          runOnce:
            deploy:
              steps:
                - task: AzureWebApp@1
                  inputs:
                    azureSubscription: 'my-azure-connection'
                    appName: 'my-app-service'
                    package: '$(Pipeline.Workspace)/drop/app.zip'

💡 Environments and Approvals

Azure DevOps Environments let you add manual approval gates between stages. Go to Pipelines → Environments → your environment → Approvals and checks to require a reviewer before production deploys.

Pipeline Variables and Key Vault Integration

  • Store non-sensitive config in Variable Groups (Pipelines → Library)
  • Link an Azure Key Vault to a Variable Group for automatic secret injection
  • Reference variables as $(variableName) anywhere in your YAML
  • Use `${{ if eq(variables.environment, "prod") }}` for conditional steps

⚠️ Security Best Practice

Never hard-code secrets, connection strings, or passwords in your YAML file. Even if your repo is private today, it may become public — and Git history is permanent.

Our Azure DevOps training covers YAML pipelines in full depth — from basic builds to multi-stage enterprise delivery pipelines with environment approvals, artifact management, and Key Vault integration.

Ready to Start Your Cloud Journey?

Join our live batch — Azure: 9–10 AM · AWS: 10:15–11:30 AM IST, Mon–Sat. Hands-on labs, exam prep, and community support.

🎓 Join Free DemoWhatsApp Us

Keep Reading

☁️
Azure

Complete AZ-104 Study Guide 2025: 8-Week Plan to Pass First Attempt

A proven week-by-week study plan for the Azure Administrator Associate exam. Covers all 5 domains with practice questions, real-world labs, and exam-day strategy.

15 Oct 2024·12 min read
Read →
⚙️
Kubernetes

Kubernetes vs Docker Swarm: Which Should You Learn in 2025?

An honest comparison for DevOps engineers choosing between K8s and Swarm. Career demand data, feature comparison, and a clear recommendation included.

22 Sep 2024·8 min read
Read →