Steps

Steps are the most fundamental building blocks of an Azure DevOps pipeline. Each step represents a single action to be performed during the execution of a job. When you define a pipeline with steps and without explicitly defining jobs, Azure DevOps will create an implicit job to contain those steps.

Step Schema

steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ] # Required. A list of steps to run in this job.
strategy: strategy # Execution strategy for this job.
continueOnError: string # Continue running even on failure?
pool: string | pool # Pool where jobs in this pipeline will run unless otherwise specified.
container: string | container # Container resource name.
services: # Container resources to run as a service container.
  string: string # Name/value pairs
workspace: # Workspace options on the agent.
  clean: string # Which parts of the workspace should be scorched before fetching.
name: string # Pipeline run number.
appendCommitMessageToRunName: boolean # Append the commit message to the build number. The default is true.
trigger: none | trigger | [ string ] # Continuous integration triggers.
parameters: [ parameter ] # Pipeline template parameters.
pr: none | pr | [ string ] # Pull request triggers.
schedules: [ cron ] # Scheduled triggers.
resources: # Containers and repositories used in the build.
  builds: [ build ] # List of build resources referenced by the pipeline.
  containers: [ container ] # List of container images.
  pipelines: [ pipeline ] # List of pipeline resources.
  repositories: [ repository ] # List of repository resources.
  webhooks: [ webhook ] # List of webhooks.
  packages: [ package ] # List of package resources.
variables: variables | [ variable ] # Variables for this pipeline.
lockBehavior: string # Behavior lock requests from this stage should exhibit in relation to other exclusive lock requests.

Step Types

Azure DevOps Pipelines supports several types of steps:

Task

A task is a pre-packaged script that performs a specific action. Azure DevOps provides many built-in tasks, and you can also use tasks from the marketplace.

Script

A script step runs a command-line script using cmd.exe on Windows and sh on other platforms.

PowerShell

A PowerShell step runs a script using PowerShell on Windows, macOS, and Linux.

Bash

A bash step runs a script using Bash on Windows, macOS, and Linux.

Checkout

The checkout step is used to check out source code from a repository.

Download

The download step downloads artifacts from the current or another pipeline run.

Publish

The publish step publishes (uploads) a file or folder as a pipeline artifact.

Template

The template step includes steps from a template file.

Step Properties

Common properties that can be applied to steps include:

displayName

A friendly name displayed in the Azure DevOps UI.

name

A reference name used in expressions.

condition

A condition that determines whether the step should run.

continueOnError

Whether to continue running more steps even if this step fails.

env

Environment variables to set for the step.

timeoutInMinutes

The maximum time a step should run before it is canceled.

workingDirectory

The working directory for the step.

Examples

Basic Pipeline with Steps

Multiple Step Types

Conditional Step Execution

Using Output Variables

Step Templates

Advanced Container Example

Best Practices for Steps

  1. Use descriptive displayNames: Give each step a clear, descriptive name to make pipeline logs easier to read.

  2. Group related commands: Use multi-line scripts for related commands rather than multiple separate script steps.

  3. Set timeouts: For steps that might hang, set timeoutInMinutes to prevent the pipeline from waiting indefinitely.

  4. Handle errors appropriately: Use continueOnError for non-critical steps where failures shouldn't stop the pipeline.

  5. Use conditions effectively: Apply conditions to skip unnecessary steps based on branch name, previous results, etc.

  6. Use step templates for reusability: Extract common sequences of steps into templates to avoid repetition.

  7. Leverage built-in expressions: Use Azure Pipelines expressions like succeeded(), failed(), always() for conditional execution.

  8. Manage working directories: Set the appropriate workingDirectory for each step rather than using cd commands.

  9. Be mindful of step order: Arrange steps in a logical order of dependency to ensure proper execution flow.

  10. Publish artifacts: Always publish important build artifacts to make them available to later stages and for troubleshooting.

Last updated