Multiple jobs

Azure Pipelines | TFS 2018 | TFS 2017

Note

Build and release pipelines are called definitions in TFS 2018 and in older versions. Service connections are called service endpoints in TFS 2018 and in older versions.

You can add multiple jobs to a pipeline. By using different jobs in a pipeline, you can:

  • Partition your pipeline into sections targeting different agent pools
  • Partition your pipeline into sections targeting different sets of self-hosted agents using different demands
  • Partition your pipeline into sections that run on agents and those that run without an agent
  • Publish build artifacts in one job and consume those in subsequent jobs
  • Pause the deployment in the middle using a manual intervention task
  • Reduce build time by running multiple jobs in parallel
  • Reduce deployment time by selectively downloading different artifacts in different jobs of a deployment pipeline
  • Conditionally execute a set of tasks
  • Partition your process into sections targeting different agent pools
  • Partition your process into sections targeting different sets of self-hosted agents using different demands
  • Partition your process into sections that run on agents and those that run without an agent
  • Publish build artifacts in one job and consume those in subsequent jobs
  • Pause the deployment in the middle using a manual intervention task
  • Reduce deployment time by selectively downloading different artifacts in different jobs of a deployment process
  • Conditionally execute a set of tasks
  • Partition your process into sections targeting different agent pools
  • Partition your process into sections targeting different sets of self-hosted agents using different demands
  • Partition your process into sections that run on agents and those that run without an agent
  • Pause the deployment in the middle using a manual intervention task

Note

Jobs are not supported in build pipelines in TFS 2017.

Note

Each agent can run only one job at a time. To run multiple jobs in parallel you must configure multiple agents. You also need sufficient parallel jobs.

The syntax for defining multiple jobs and their dependencies is:

jobs:
- job: string
  dependsOn: string
  condition: string

YAML builds are not yet available on TFS.

Dependencies

Example jobs that build sequentially:

jobs:
- job: Debug
  steps:
  - script: echo hello from the Debug build
- job: Release
  dependsOn: Debug
  steps:
  - script: echo hello from the Release build

Example jobs that build in parallel (no dependencies):

jobs:
- job: Windows
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - script: echo hello from Windows
- job: macOS
  pool:
    vmImage: 'macOS-10.13'
  steps:
  - script: echo hello from macOS
- job: Linux
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - script: echo hello from Linux

Example of fan out:

jobs:
- job: InitialJob
  steps:
  - script: echo hello from initial job
- job: SubsequentA
  dependsOn: InitialJob
  steps:
  - script: echo hello from subsequent A
- job: SubsequentB
  dependsOn: InitialJob
  steps:
  - script: echo hello from subsequent B

Example of fan in:

jobs:
- job: InitialA
  steps:
  - script: echo hello from initial A
- job: InitialB
  steps:
  - script: echo hello from initial B
- job: Subsequent
  dependsOn:
  - InitialA
  - InitialB
  steps:
  - script: echo hello from subsequent

YAML is not yet supported in TFS.

Conditions

You can specify the conditions under which each job runs. By default, a job runs if it does not depend on any other job, or if all of the jobs that it depends on have completed and succeeded. You can customize this behavior by forcing a job to run even if a previous job fails or by specifying a custom condition.

YAML builds are not yet available on TFS.

Example to run a job based upon the status of running a previous job:

jobs:
- job: A
  steps:
  - script: exit 1

- job: B
  dependsOn: A
  condition: failed()
  steps:
  - script: echo this will run when A fails

- job: C
  dependsOn:
  - A
  - B
  condition: succeeded('B')
  steps:
  - script: echo this will run when B runs and succeeds

Example of using a custom condition:

jobs:
- job: A
  steps:
  - script: echo hello

- job: B
  dependsOn: A
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
  steps:
  - script: echo this only runs for master

You can specify that a job run based on the value of an output variable set in a previous job. In this case, you can only use variables set in directly dependent jobs:

jobs:
- job: A
  steps:
  - script: "echo ##vso[task.setvariable variable=skipsubsequent;isOutput=true]false"
    name: printvar

- job: B
  condition: and(succeeded(), ne(dependencies.A.outputs['printvar.skipsubsequent'], 'true'))
  dependsOn: A
  steps:
  - script: echo hello from B