0
0
AzureHow-ToBeginner · 4 min read

How to Use Azure Pipelines: Simple Guide for Beginners

To use Azure Pipelines, create a YAML file that defines your build and deployment steps, then connect it to your code repository in Azure DevOps. The pipeline runs automatically on code changes, building and deploying your app as defined.
📐

Syntax

An Azure Pipeline is defined using a azure-pipelines.yml file. This file contains stages, jobs, and steps that describe what actions to perform.

  • trigger: Defines when the pipeline runs (e.g., on code push).
  • pool: Specifies the agent machine to run the pipeline.
  • steps: Lists commands or tasks to execute.
yaml
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: echo Hello, Azure Pipelines!
    displayName: 'Run a one-line script'
💻

Example

This example shows a simple pipeline that runs on every push to the main branch. It uses an Ubuntu agent and runs a script that prints a message.

yaml
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: |
      echo "Starting build process"
      echo "Build completed successfully"
    displayName: 'Build Script'
Output
Starting build process Build completed successfully
⚠️

Common Pitfalls

Common mistakes include:

  • Not specifying the correct branch in trigger, so the pipeline never runs.
  • Using an unsupported agent image or missing pool definition.
  • Incorrect indentation or syntax errors in the YAML file.
  • Forgetting to commit the azure-pipelines.yml file to the repository.

Always validate your YAML syntax and check pipeline logs for errors.

yaml
trigger:
  branches:
    include:
      - main  # Correct branch name if your main branch is 'main'

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: echo "Hello"
    displayName: 'Say Hello'
📊

Quick Reference

Remember these tips when using Azure Pipelines:

  • Use trigger to control when pipelines run.
  • Choose the right pool agent for your tasks.
  • Define clear steps with scripts or tasks.
  • Commit your YAML file to the root of your repo.
  • Check pipeline run logs for troubleshooting.

Key Takeaways

Create an azure-pipelines.yml file to define your pipeline steps.
Use the trigger section to specify when the pipeline runs.
Select an appropriate agent pool to run your jobs.
Validate YAML syntax to avoid pipeline failures.
Commit the pipeline file to your repository root for Azure DevOps to detect it.