Bird
Raised Fist0
Azurecloud~5 mins

Azure Pipelines overview - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Azure Pipelines helps you automatically build and test your code every time you make a change. It solves the problem of manually checking and deploying code by running these steps for you in the cloud.
When you want to check your code for errors automatically after every change.
When you want to build your app and prepare it for release without doing it by hand.
When you want to run tests on your code to catch problems early.
When you want to deploy your app to a server or cloud automatically after building.
When you want to share your build and test process with your team for consistency.
Config File - azure-pipelines.yml
azure-pipelines.yml
trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

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

- script: |
    python -m pip install --upgrade pip
    pip install -r requirements.txt
  displayName: 'Install dependencies'

- script: |
    python -m unittest discover
  displayName: 'Run tests'

This file tells Azure Pipelines to start a build when code is pushed to the main branch.

It uses a Linux machine with Python installed.

Steps include installing Python dependencies and running tests automatically.

Commands
This command creates a new Azure Pipeline named 'example-pipeline' linked to the specified GitHub repository and branch, using the YAML file for configuration.
Terminal
az pipelines create --name example-pipeline --repository https://github.com/example/repo.git --branch main --yml-path azure-pipelines.yml
Expected OutputExpected
Pipeline 'example-pipeline' created successfully.
→
--name - Sets the name of the pipeline
→
--repository - Specifies the Git repository URL
→
--yml-path - Points to the pipeline YAML configuration file
This command starts a run of the 'example-pipeline' to build and test the code immediately.
Terminal
az pipelines run --name example-pipeline
Expected OutputExpected
Run started for pipeline 'example-pipeline'.
→
--name - Specifies which pipeline to run
This command lists the most recent run of the 'example-pipeline' so you can check its status and results.
Terminal
az pipelines runs list --pipeline-name example-pipeline --top 1
Expected OutputExpected
[ { "id": 123, "status": "completed", "result": "succeeded", "pipelineName": "example-pipeline" } ]
→
--pipeline-name - Filters runs by pipeline name
→
--top - Limits the number of runs shown
Key Concept

If you remember nothing else from this pattern, remember: Azure Pipelines automates building and testing your code every time you change it, so you catch problems early and save time.

Common Mistakes
Not specifying the correct YAML file path when creating the pipeline
The pipeline won't run because it can't find the instructions to build and test your code.
Always use the --yml-path flag with the correct path to your azure-pipelines.yml file.
Triggering the pipeline on the wrong branch
Your pipeline might not run when you expect it to, missing important builds or tests.
Set the trigger branch in the YAML file to the branch you want to monitor, like 'main'.
Summary
Create an Azure Pipeline using a YAML file to define build and test steps.
Run the pipeline manually to check your code immediately.
List pipeline runs to see the status and results of your builds.

Practice

(1/5)
1. What is the main purpose of Azure Pipelines?
easy
A. To automate building, testing, and deploying code
B. To store large amounts of data
C. To create virtual machines
D. To monitor network traffic

Solution

  1. Step 1: Understand Azure Pipelines role

    Azure Pipelines automate the process of building, testing, and deploying code changes.
  2. Step 2: Compare options with purpose

    Options B, C, and D describe other Azure services, not pipelines.
  3. Final Answer:

    To automate building, testing, and deploying code -> Option A
  4. Quick Check:

    Azure Pipelines = automate build/test/deploy [OK]
Hint: Remember pipelines automate code workflows [OK]
Common Mistakes:
  • Confusing pipelines with storage services
  • Thinking pipelines create virtual machines
  • Mixing pipelines with monitoring tools
2. Which file format is commonly used to define Azure Pipelines?
easy
A. .json
B. .txt
C. .xml
D. .yaml

Solution

  1. Step 1: Identify pipeline definition format

    Azure Pipelines use YAML files to define build and deployment steps.
  2. Step 2: Eliminate other formats

    JSON, XML, and TXT are not standard for pipeline definitions in Azure.
  3. Final Answer:

    .yaml -> Option D
  4. Quick Check:

    Pipeline config = YAML file [OK]
Hint: YAML files define pipeline steps clearly [OK]
Common Mistakes:
  • Choosing JSON instead of YAML
  • Confusing XML with pipeline config
  • Thinking plain text files define pipelines
3. Given this YAML snippet in an Azure Pipeline:
trigger:
  branches:
    include:
      - main

steps:
- script: echo Hello, world!

What happens when you push code to the main branch?
medium
A. The pipeline fails due to syntax error
B. The pipeline ignores the push
C. The pipeline runs and prints 'Hello, world!'
D. The pipeline runs but does nothing

Solution

  1. Step 1: Understand trigger configuration

    The pipeline triggers on pushes to the 'main' branch as specified.
  2. Step 2: Analyze steps section

    The single step runs a script that echoes 'Hello, world!'.
  3. Final Answer:

    The pipeline runs and prints 'Hello, world!' -> Option C
  4. Quick Check:

    Trigger on main runs echo script [OK]
Hint: Trigger on branch runs defined script [OK]
Common Mistakes:
  • Assuming pipeline ignores main branch
  • Thinking pipeline does nothing on trigger
  • Believing syntax error exists in snippet
4. You wrote this YAML for Azure Pipelines but it never triggers:
trigger:
  branches:
    exclude:
      - main

steps:
- script: echo Build started

What is the likely problem?
medium
A. The pipeline excludes the main branch, so pushes to main don't trigger it
B. The script syntax is incorrect
C. The trigger keyword is misspelled
D. The pipeline requires a separate build agent

Solution

  1. Step 1: Review trigger exclude setting

    The pipeline excludes the 'main' branch, so pushes to 'main' won't start it.
  2. Step 2: Check other parts

    The script syntax and trigger keyword are correct; no build agent issue is indicated.
  3. Final Answer:

    The pipeline excludes the main branch, so pushes to main don't trigger it -> Option A
  4. Quick Check:

    Exclude main branch stops trigger [OK]
Hint: Exclude means branch won't trigger pipeline [OK]
Common Mistakes:
  • Thinking script syntax is wrong
  • Assuming trigger keyword typo
  • Believing build agent is missing
5. You want to run tests only when code is pushed to the develop branch and deploy only when code is pushed to main. How should you configure triggers in your Azure Pipelines YAML?
hard
A. Use a single pipeline triggered on both branches and run all steps always
B. Use two separate pipelines: one triggered on 'develop' for tests, another on 'main' for deploy
C. Trigger only on 'main' and manually run tests
D. Trigger only on 'develop' and deploy manually

Solution

  1. Step 1: Understand branch-specific triggers

    Running tests and deploy on different branches requires separate triggers.
  2. Step 2: Choose pipeline structure

    Two pipelines allow independent triggers and steps per branch, matching requirements.
  3. Step 3: Evaluate other options

    Single pipeline running all steps always doesn't separate concerns; manual runs reduce automation benefits.
  4. Final Answer:

    Use two separate pipelines: one triggered on 'develop' for tests, another on 'main' for deploy -> Option B
  5. Quick Check:

    Separate pipelines for branch-specific tasks [OK]
Hint: Separate pipelines for different branch tasks [OK]
Common Mistakes:
  • Using one pipeline for all branches without conditions
  • Triggering only on main and skipping tests automation
  • Triggering only on develop and missing deploy automation