Exploring the anatomy of Pipeline in Azure DevOps
A pipeline in Azure DevOps consists of multiple components that define its structure and behavior. Each component plays a role in orchestrating builds, tests, and deployments.
Here’s a detailed breakdown.
1. Name
The pipeline’s name is an identifier that appears in the Azure DevOps UI to help users distinguish between pipeline runs.
Usage
Define a name to provide context (e.g., include the branch, build number, or timestamp).
Can be set dynamically using variables.
Example
xxxxxxxxxx11name'MyPipeline-$(Build.BuildId)'$(Build.BuildId)is a system variable representing the unique build ID.
2. Trigger
Defines when the pipeline should start. Azure Pipelines supports multiple types of triggers.
Types
Continuous Integration (CI): Triggers on code changes.
Pull Request (PR): Triggers for PR validation.
Scheduled: Runs pipelines at specific times.
Manual: Starts pipelines only on demand.
Example
xxxxxxxxxx51trigger2main3develop4pr5feature/CI Trigger: Runs on changes to
mainanddevelop.PR Trigger: Runs for PRs targeting branches matching
feature/.
3. Variables
Variables store values that can be reused throughout the pipeline.
They can be:
Static: Hardcoded values.
Dynamic: System or custom variables generated at runtime.
Secure: Stored securely in Azure DevOps as secrets.
Example
xxxxxxxxxx31variables2buildConfiguration'Release'3isProductionfalse$(buildConfiguration)is used in steps for configuration settings.$(isProduction)can control conditional logic.
4. Job
A job is a collection of steps that execute on an agent. Pipelines can have multiple jobs running sequentially or in parallel.
Key Features
Display Name: Human-readable name for the job.
Dependencies: Specify dependencies between jobs.
Conditionals: Execute jobs conditionally based on variables.
Example
xxxxxxxxxx51jobs2jobBuildJob3displayName'Build the application'4steps5scriptecho Building...
5. Pool
The pool specifies the agent (VM) to execute the job.
Azure DevOps offers:
Microsoft-Hosted Agents: Preconfigured with tools.
Self-Hosted Agents: Custom-configured machines.
Example
xxxxxxxxxx21pool2vmImage'ubuntu-latest'ubuntu-latest: A Microsoft-hosted agent running Ubuntu.For a self-hosted agent:
xxxxxxxxxx21pool2name'MySelfHostedPool'
6. Checkout
The checkout step determines the code repository and branch to be fetched for the pipeline.
Usage
Checkout the repository containing the pipeline definition.
Use custom repositories for additional resources.
Example
xxxxxxxxxx31steps2checkoutself3cleantrueself: Refers to the pipeline’s main repository.clean: true: Ensures a clean slate by deleting untracked files.
7. Steps
Steps are the smallest executable units in a pipeline. They define specific tasks or commands.
Types
Script Steps: Run shell or PowerShell commands.
Task Steps: Use predefined tasks (e.g., build, test, deploy).
Manual/Approval Steps: Require manual intervention (in deployment pipelines).
Example: Script Step
xxxxxxxxxx31steps2scriptecho "Building the project..."3displayName'Run Build Command'Example: Task Step
xxxxxxxxxx51steps2taskUseDotNet@23inputs4packageType'sdk'5version'6.x'
Putting It All Together
Here’s a complete YAML pipeline example for a .NET project:
xxxxxxxxxx231name'MyPipeline-$(Build.BuildId)'2trigger3main4variables5 buildConfiguration'Release'6jobs7jobBuildJob8 displayName'Build and Test'9 pool10 vmImage'windows-latest'11 steps12checkoutself13 cleantrue14taskUseDotNet@215 inputs16 packageType'sdk'17 version'6.x'18scriptdotnet restore19 displayName'Restore Dependencies'20scriptdotnet build --configuration $(buildConfiguration)21 displayName'Build Solution'22scriptdotnet test --configuration $(buildConfiguration) --collect"Code Coverage"23 displayName'Run Tests'Summary
| Component | Description |
|---|---|
| Name | Identifies the pipeline run. |
| Trigger | Specifies conditions for pipeline execution (CI, PR, schedule, or manual). |
| Variables | Stores reusable values (static, dynamic, or secure). |
| Job | A collection of steps executed on a single agent. |
| Pool | Defines the type of agent to run the pipeline (Microsoft-hosted or self-hosted). |
| Checkout | Fetches source code for the pipeline. |
| Steps | Smallest unit of execution (script or predefined tasks). |






















Leave a Reply