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
Build pipeline basics
📖 Scenario: You are working on a software project and want to automate the process of building your code whenever you make changes. This helps catch errors early and saves time.We will create a simple build pipeline configuration file that defines the steps to build your project automatically.
🎯 Goal: Build a basic Azure DevOps pipeline YAML file that defines a trigger, a pool, and a build step to compile your code.
📋 What You'll Learn
Create a YAML file named azure-pipelines.yml
Define a trigger on the main branch
Specify the build agent pool as ubuntu-latest
Add a build step to run a shell command echo Building project...
💡 Why This Matters
🌍 Real World
Automating builds saves time and reduces errors by running builds automatically when code changes.
💼 Career
Understanding build pipelines is essential for DevOps roles to ensure continuous integration and delivery.
Progress0 / 4 steps
1
Create the pipeline trigger
Create a YAML file named azure-pipelines.yml and add a trigger section that triggers the pipeline on the main branch only. Write exactly trigger: followed by - main on the next line.
Azure
Hint
The trigger section tells Azure DevOps which branches to watch for changes.
2
Add the build agent pool
Below the trigger section, add a pool section with vmImage: 'ubuntu-latest' to specify the build agent. Use exactly pool: and vmImage: 'ubuntu-latest' with correct indentation.
Azure
Hint
The pool section tells Azure DevOps which machine image to use for running the build.
3
Add a build step
Add a steps section below pool. Inside steps, add a script step that runs the shell command echo Building project.... Use exactly - script: echo Building project... with correct indentation.
Azure
Hint
The steps section defines the commands to run during the build.
4
Display the complete pipeline
Print the complete contents of the azure-pipelines.yml file to verify your pipeline configuration.
Azure
Hint
Use a print statement to show the full YAML content exactly as written.
Practice
(1/5)
1. What is the main purpose of a build pipeline in Azure DevOps?
easy
A. To manually test code changes
B. To store code in a repository
C. To automate the process of preparing code for deployment
D. To monitor user activity on a website
Solution
Step 1: Understand the role of a build pipeline
A build pipeline automates tasks like compiling code and running tests when code changes.
Step 2: Identify the main goal
The main goal is to prepare code automatically for deployment or further steps.
Final Answer:
To automate the process of preparing code for deployment -> Option C
Hint: Build pipelines automate code prep, not manual tasks [OK]
Common Mistakes:
Confusing build pipeline with code repository
Thinking build pipelines monitor user activity
Assuming build pipelines are for manual testing
2. Which YAML snippet correctly defines a trigger for a build pipeline on the 'main' branch?
easy
A. trigger:\n branches:\n - main
B. trigger:\n branches:\n exclude:\n - main
C. trigger:\n paths:\n include:\n - main
D. trigger:\n branches:\n include:\n - main
Solution
Step 1: Understand trigger syntax in YAML
The trigger block uses 'branches' with 'include' to specify branches that start the pipeline.
Step 2: Check each option
trigger:\n branches:\n include:\n - main correctly includes 'main' branch under 'branches' and 'include'. trigger:\n branches:\n exclude:\n - main excludes 'main', which disables trigger on it. trigger:\n paths:\n include:\n - main uses 'paths' which triggers on file changes, not branches. trigger:\n branches:\n - main misses 'include' keyword, so syntax is incorrect.
Final Answer:
trigger:\n branches:\n include:\n - main -> Option D
Quick Check:
Correct trigger syntax includes branches: include [OK]
Hint: Use 'branches: include:' to trigger on specific branches [OK]
Common Mistakes:
Using 'exclude' instead of 'include' to trigger
Confusing 'paths' with 'branches' in triggers
Omitting 'include' keyword causing syntax errors
3. Given this YAML snippet in an Azure build pipeline, what will be the output of the script step?
5. You want to create a build pipeline that triggers only when files in the 'src/' folder change on the 'release' branch. Which YAML snippet correctly sets this up?
hard
A. trigger:\n branches:\n include:\n - release\n paths:\n include:\n - src/**
B. trigger:\n branches:\n include:\n - release\n paths:\n exclude:\n - src/**
C. trigger:\n branches:\n exclude:\n - release\n paths:\n include:\n - src/**
D. trigger:\n branches:\n include:\n - main\n paths:\n include:\n - src/**
Solution
Step 1: Understand branch and path filters
To trigger on 'release' branch and only when files in 'src/' change, include 'release' in branches and 'src/**' in paths.
Step 2: Evaluate each option
trigger:\n branches:\n include:\n - release\n paths:\n include:\n - src/** correctly includes 'release' branch and 'src/**' path. trigger:\n branches:\n include:\n - release\n paths:\n exclude:\n - src/** excludes 'src/**' so it won't trigger on those files. trigger:\n branches:\n exclude:\n - release\n paths:\n include:\n - src/** excludes 'release' branch, so no trigger on it. trigger:\n branches:\n include:\n - main\n paths:\n include:\n - src/** triggers on 'main' branch, not 'release'.