1. What are Stages, Jobs, Steps, and Tasks?
In Azure Pipelines, Stages, Jobs, Steps, and Tasks are the building blocks used to organize and execute CI/CD workflows.
Each component has a specific responsibility.
|
Component |
Description |
Example |
|---|---|---|
|
Stage |
Major phase of a pipeline |
Build, Test, Deploy |
|
Job |
Collection of steps executed on an agent or server |
BuildJob, TestJob |
|
Step |
Individual operation inside a job |
Restore, Build, Test |
|
Task |
Predefined operation provided by Azure Pipelines |
|
Important: A task is a type of step. Tasks and script steps are both defined inside a job.
2. Execution Hierarchy
The execution hierarchy is:
Pipeline
Complete CI/CD workflowBuild Stage
CIDeploy Stage
CDBuildJob
JobDeployJob
JobStep 1
Restore packagesStep 2
Build applicationStep 3
Run testsStep 1
Download artifactStep 2
Deploy applicationThe hierarchy is:
Pipeline
└── Stage
└── Job
└── Step
├── Task
└── Script
3. What is a Stage?
A Stage is a major logical division of a pipeline.
Stages are commonly used to separate different phases of the CI/CD process.
Examples:
-
Build Stage
-
Test Stage
-
SIT Deployment Stage
-
UAT Deployment Stage
-
Production Deployment Stage
YAML example
stages:
- stage: Build
displayName: 'Build Stage'
jobs:
- job: BuildJob
steps:
- script: echo "Building Application"
Key points:
-
A pipeline can contain multiple stages.
-
Each stage contains one or more jobs.
-
Stages can run sequentially or in parallel, depending on dependencies.
-
Stages support conditions and dependencies.
-
Approvals can control deployment stages through protected resources such as environments.
4. What is a Job?
A Job is a collection of steps executed together.
A job typically runs on an Azure Pipelines agent.
For example, the Build stage might contain two jobs:
-
BuildJob – compiles the application.
-
TestJob – executes unit tests.
YAML example
jobs:
- job: BuildJob
pool:
vmImage: 'windows-latest'
steps:
- script: dotnet build
- job: TestJob
pool:
vmImage: 'windows-latest'
steps:
- script: dotnet test
Key points:
-
A stage can contain multiple jobs.
-
Jobs can run in parallel when agents are available.
-
Use
dependsOnto execute jobs sequentially. -
Each agent job runs on an agent.
-
Different jobs may run on different machines.
-
Jobs can also be deployment, server, or container jobs.
5. What is a Step?
A Step is an individual operation performed inside a job.
Steps can execute scripts or predefined tasks.
YAML example
steps:
- script: dotnet restore
displayName: 'Restore Packages'
- script: dotnet build
displayName: 'Build Application'
- script: dotnet test
displayName: 'Run Unit Tests'
Key points:
-
A job contains one or more steps.
-
Steps execute sequentially within a job.
-
Steps in the same agent job share the same agent and workspace.
-
If a step fails, subsequent steps normally do not execute unless conditions permit.
6. What is a Task?
A Task is a predefined operation available in Azure Pipelines.
Instead of writing commands manually, you can use built-in tasks.
For example:
|
Task |
Purpose |
|---|---|
|
|
Install .NET SDK |
|
|
Restore, build, test, or publish .NET applications |
|
|
Publish build artifacts |
|
|
Deploy to Azure App Service |
|
|
Copy files between directories |
YAML example
steps:
- task: DotNetCoreCLI@2
displayName: 'Build Application'
inputs:
command: 'build'
projects: '**/*.csproj'
Here:
-
taskspecifies the predefined Azure Pipelines task. -
DotNetCoreCLIis the task name. -
@2indicates the major version. -
inputsprovides configuration values.
Difference between Step and Task
steps:
# Script Step
- script: dotnet build
# Task Step
- task: DotNetCoreCLI@2
inputs:
command: 'build'
Both perform a build operation.
The difference is that the script directly executes a command, while the task uses a predefined Azure Pipelines implementation.
7. Complete YAML Example
The following example demonstrates the hierarchy using an ASP.NET Core application.
trigger:
- main
pool:
vmImage: 'windows-latest'
stages:
# Stage 1
- stage: Build
displayName: 'Build Stage'
jobs:
# Job 1
- job: BuildJob
displayName: 'Build Application'
steps:
# Step 1
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.0.x'
# Step 2
- script: dotnet restore
displayName: 'Restore Packages'
# Step 3
- script: dotnet build --no-restore
displayName: 'Build Application'
# Job 2
- job: TestJob
displayName: 'Run Tests'
dependsOn: BuildJob
steps:
- script: dotnet test
displayName: 'Execute Unit Tests'
# Stage 2
- stage: Deploy
displayName: 'Deployment Stage'
dependsOn: Build
jobs:
- job: DeployJob
steps:
- script: echo "Deploying Application"
displayName: 'Deployment Placeholder'
Execution sequence:
Build Stage
|
v
BuildJob
|
├── Install .NET SDK
├── Restore Packages
└── Build Application
|
v
TestJob
|
└── Execute Unit Tests
|
v
Deploy Stage
|
v
DeployJob
|
└── Deployment Placeholder
Note that the deployment step above only prints a message. An actual CD pipeline needs artifact publishing, artifact downloading, and deployment tasks.
8. Sequential vs Parallel Execution
|
Component |
Default behavior |
Can run in parallel? |
|---|---|---|
|
Stages |
Sequential by default |
Yes, using dependencies |
|
Jobs |
Parallel by default when independent |
Yes |
|
Steps |
Sequential |
Not directly within the same job |
|
Tasks |
Execute as steps |
Separate jobs can execute tasks concurrently |
For example, to run jobs sequentially:
jobs:
- job: BuildJob
steps:
- script: dotnet build
- job: TestJob
dependsOn: BuildJob
steps:
- script: dotnet test
To allow both jobs to run independently:
jobs:
- job: BuildJob
steps:
- script: dotnet build
- job: TestJob
steps:
- script: dotnet test
Parallel execution also depends on available agents and parallel-job capacity.
9. Important Interview Questions
Q1. What is the execution hierarchy in Azure Pipelines?
Pipeline → Stage → Job → Step. A step can be a predefined task or a script.
Q2. Can a stage contain multiple jobs?
Yes. A stage can contain multiple jobs that execute sequentially or in parallel.
Q3. Can steps run in parallel within the same job?
No. Steps in a single job execute sequentially. To run operations in parallel, use separate jobs.
Q4. What is the difference between a job and a step?
A job is a collection of steps executed as a unit. A step is an individual operation within that job.
Q5. What is the difference between a task and a script?
A task is a predefined Azure Pipelines operation, whereas a script directly executes commands such as PowerShell, Bash, or dotnet build.
Q6. What is dependsOn?
dependsOn defines dependencies between stages or jobs and helps control their execution order.
10. Interview-ready Answer
Azure Pipelines uses a hierarchical structure consisting of Pipeline, Stage, Job, and Step.
A Pipeline represents the complete CI/CD workflow. A Stage represents a major phase such as Build, Test, or Deployment. Each stage contains one or more Jobs, and each job contains multiple Steps.
Steps perform individual operations using scripts or predefined Tasks.
By default, stages execute sequentially, independent jobs can execute in parallel, and steps within a job execute sequentially.
We use
dependsOnto control execution dependencies between stages and jobs.
Key point to remember: A Stage organizes jobs, a Job organizes steps, and a Task is a predefined type of step.