Jobs

Jobs are the building blocks of an Azure DevOps pipeline that represent units of work assignable to a single agent. Jobs run in sequence or parallel within a stage and contain a series of steps that run sequentially on the same agent.

Job Schema

jobs: [ job | deployment | template ] # Required. Jobs represent units of work which can be assigned to a single agent or server.
pool: string | pool # Pool where jobs in this pipeline will run unless otherwise specified.
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.

Individual Job Schema

Basic Example

Advanced Examples

Jobs with Dependencies

Matrix Strategy

Matrix strategy is used to run the same job multiple times with different variable sets:

Job Conditions

Job with Container

Deployment Jobs

Deployment jobs are a special type of job that records deployment history:

Job Templates

Job Types

Azure DevOps Pipelines supports three types of jobs:

1. Agent Jobs

Standard jobs that run on an agent. These are the most common type.

2. Deployment Jobs

Jobs that record deployment history.

3. Server Jobs

Jobs that run on the Azure DevOps server without an agent.

Best Practices for Jobs

  1. Use Descriptive Names: Give jobs meaningful names and display names to improve readability.

  2. Define Clear Dependencies: Use dependsOn to create a clear execution flow between jobs.

  3. Set Appropriate Timeouts: Use timeoutInMinutes to prevent jobs from running indefinitely.

  4. Use Job Templates for Reusability: Extract common job patterns into templates.

  5. Leverage Job Conditions: Use conditions to control when jobs should run.

  6. Use Matrix Strategy Efficiently: Use matrix when you need to run the same job with multiple configurations.

  7. Consider Parallelization: Use parallel jobs when possible to reduce total pipeline run time.

  8. Use Job Outputs for Sharing Data: Use job outputs to pass data between jobs.

  9. Use Specialized Pools for Specialized Jobs: Match job requirements to appropriate agent pools.

  10. Minimize Job Dependencies: Break complex workflows into parallel paths where possible to optimize execution time.

Last updated