Using Azure DevOps Pipelines | Generated by AI

Home 2025.03

Let’s break this down into two parts: using Azure DevOps Pipelines and writing YAML for pipelines. I’ll provide a clear, practical explanation for both.


How to Use Azure DevOps Pipelines

Azure DevOps Pipelines is a CI/CD (Continuous Integration/Continuous Deployment) tool that automates building, testing, and deploying code. Here’s how to get started:

1. Set Up a Project

2. Connect Your Code

3. Create a Pipeline

4. Define the Pipeline

5. Run and Monitor

6. Deploy (Optional)


How to Write YAML for Azure Pipelines

YAML (Yet Another Markup Language) is a human-readable format used to define pipeline configurations. Here’s a crash course:

Basic Structure

trigger:
  - main  # Run pipeline when 'main' branch is updated

pool:
  vmImage: 'ubuntu-latest'  # Specify the build agent (e.g., Ubuntu, Windows, macOS)

steps:
  - script: echo Hello, world!  # A simple command to run
    displayName: 'Run a one-line script'

Common Elements

  1. Variables:

    variables:
      buildConfiguration: 'Release'
    steps:
      - script: echo $(buildConfiguration)  # Outputs 'Release'
    
  2. Jobs (group steps):

    jobs:
    - job: Build
      steps:
        - script: echo Building...
    - job: Test
      steps:
        - script: echo Testing...
    
  3. Tasks (pre-built actions):

    steps:
      - task: DotNetCoreCLI@2  # Example: Build a .NET project
        inputs:
          command: 'build'
          projects: '**/*.csproj'
    
  4. Conditions:

    steps:
      - script: echo This runs only on main
        condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
    
  5. Stages (for multi-phase pipelines):

    stages:
    - stage: Build
      jobs:
        - job: BuildJob
          steps:
            - script: echo Building...
    - stage: Deploy
      dependsOn: Build
      jobs:
        - job: DeployJob
          steps:
            - script: echo Deploying...
    

Real-World Example

Here’s a pipeline for a Node.js app:

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - task: NodeTool@0  # Install Node.js
    inputs:
      versionSpec: '16.x'
    displayName: 'Install Node.js'

  - script: |
      npm install
      npm run build
    displayName: 'Install and Build'

  - task: CopyFiles@2  # Copy build artifacts
    inputs:
      contents: 'dist/**'
      targetFolder: '$(Build.ArtifactStagingDirectory)'

  - task: PublishBuildArtifacts@1  # Publish artifacts
    inputs:
      pathToPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: 'dist'

Tips for Writing YAML


Next Steps

What do you want to dive deeper into? Setting up a pipeline, YAML syntax, or something else?


Back Donate