DEV Community

Akash Roy
Akash Roy

Posted on

Build Your First Azure Pipeline (YAML-based CI/CD)

Now that you’ve seen how Azure DevOps works and what role pipelines play in the DevOps lifecycle, it’s time to get hands-on. In this blog, we’ll walk through creating a complete CI/CD pipeline using YAML in Azure Pipelines.

We’ll cover:

  • Creating a new Azure DevOps project
  • Connecting your Git repo
  • Writing your first YAML pipeline
  • Running and debugging your build

Let’s go step-by-step.

Step 1: Create a New Project in Azure DevOps

  1. Go to https://dev.azure.com/ and sign in.
  2. Click on New Project.
  3. Enter project name (e.g., my-first-pipeline), select Private, and click Create.

Step 2: Push Code to Azure Repos (or Connect GitHub)

You can either:

  • Push your local project to the Azure Repo created automatically, OR
  • Connect an external GitHub repo (from Pipelines > New Pipeline > GitHub)

Make sure your repo has a basic project setup — for example, a Node.js or Python app with tests.

Step 3: Create Your First Pipeline

  1. Go to Pipelines > New Pipeline.

    New Pipeline button

  2. Choose your source (Azure Repos Git or GitHub).

    Select source

  3. Select your repository.

    Choose repository

  4. Azure will try to auto-detect a starter pipeline. You can use it or paste your own.

    Starter pipeline suggestion

Step 4: Write the YAML for CI

Here’s a basic CI pipeline for a Node.js project:

trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

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

  - script: |
      npm install
      npm test
    displayName: 'Install dependencies and run tests'

  - script: npm run build
    displayName: 'Build application'
Enter fullscreen mode Exit fullscreen mode

For Python:

trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.x'

  - script: |
      pip install -r requirements.txt
      pytest
    displayName: 'Install deps and run tests'
Enter fullscreen mode Exit fullscreen mode

Step 5: Run the Pipeline

Once committed, the pipeline will automatically run.

You’ll see:

  • Each step’s status (success/failure)
  • Logs for every command
  • Artifacts (if any) saved from the build

Step 6: Debug Failures

  • Use the logs tab to inspect each task output
  • Common issues: missing dependencies, wrong version, permission errors

Step 7: Add Deployment to Azure and Set Up an Azure Service Connection (Optional)

Before your pipeline can deploy to Azure resources, it needs a secure way to authenticate. Azure DevOps handles this using Service Connections.

To create one:

  1. Go to your Azure DevOps project
  2. Navigate to Project Settings > Service connections
  3. Click New service connection
  4. Choose Azure Resource Manager
  5. Select Service principal (automatic) (recommended)
  6. Choose your subscription and authorize access
  7. Give it a recognizable name (e.g., MyServiceConnection)

This connection will be referenced in your pipeline YAML to authorize deployments.

  - task: AzureWebApp@1
    inputs:
      azureSubscription: 'MyServiceConnection'
      appName: 'my-web-app'
      package: '$(System.DefaultWorkingDirectory)/**/*.zip'
Enter fullscreen mode Exit fullscreen mode

Best Practices

  • Use separate pipelines for CI (build/test) and CD (deploy)
  • Store your pipeline YAML in the root of your repo (azure-pipelines.yml)
  • Protect your main branch with build validation policies
  • Use variable groups and secrets via Azure Key Vault

What’s Next

In the next blog, we’ll look at using Terraform with Azure DevOps to provision infrastructure as code. We’ll start by writing a basic Terraform script to deploy a resource group, and run it from a pipeline.

From pipelines to infrastructure — this is where DevOps gets powerful.

Top comments (0)