title | description | ms.date | monikerRange |
---|---|---|---|
jobs.job.strategy definition |
Execution strategy for this job. |
10/04/2024 |
>=azure-pipelines-2019 |
:::moniker range=">=azure-pipelines-2019"
Execution strategy for this job.
:::moniker-end
:::moniker range=">=azure-pipelines-2019"
Definitions that reference this definition: pipeline, jobs.job
:::moniker-end
:::moniker range=">=azure-pipelines-2019"
Implementation | Description |
---|---|
strategy: matrix, maxParallel | Matrix job strategy. |
strategy: parallel | Parallel job strategy. |
:::moniker-end
:::moniker range=">=azure-pipelines-2019"
Use of a matrix generates copies of a job, each with different input. These copies are useful for testing against different configurations or platform versions.
strategy:
matrix: # Matrix defining the job strategy; see the following examples.
{ string1: { string2: string3 }
maxParallel: string # Maximum number of jobs running in parallel.
matrix
{ string1: { string2: string3 }.
Matrix defining the job strategy; see the following examples.
maxParallel
string.
Maximum number of jobs running in parallel.
:::moniker-end
strategy:
matrix: { string1: { string2: string3 } }
maxParallel: number
For each occurrence of string1 in the matrix, a copy of the job is generated. The name string1 is the copy's name and is appended to the name of the job. For each occurrence of string2, a variable called string2 with the value string3 is available to the job.
Note
Matrix configuration names must contain only basic Latin alphabet letters (A-Z and a-z), digits (0-9), and underscores (_
).
They must start with a letter.
Also, their length must be 100 characters or fewer.
The optional maxParallel
keyword specifies the maximum number of simultaneous matrix legs to run at once.
::: moniker range=">= azure-pipelines-2020"
If maxParallel
is unspecified or set to 0, no limit is applied.
::: moniker-end
::: moniker range=">= azure-pipelines-2019 <= azure-pipelines-2019.1"
If maxParallel
is unspecified, no limit is applied.
::: moniker-end
Note
The matrix
syntax doesn't support automatic job scaling but you can implement similar
functionality using the each
keyword. For an example, see expressions.
This example uses a matrix
job strategy to build on multiple platforms.
# Build NodeJS Express app using Azure Pipelines
# https://learn.microsoft.com/azure/devops/pipelines/ecosystems/javascript?view=azure-devops
strategy:
matrix:
linux:
imageName: 'ubuntu-latest'
mac:
imageName: 'macOS-latest'
windows:
imageName: 'windows-latest'
pool:
vmImage: $(imageName)
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
- script: |
npm install
npm test
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/TEST-RESULTS.xml'
testRunTitle: 'Test results for JavaScript'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/coverage'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
- task: PublishBuildArtifacts@1
This pipeline uses script to run in each platform's integral script interpreter: Bash on macOS and Linux, CMD on Windows. See multi-platform scripts to learn more.
The following example builds on both a self-hosted agent and a Microsoft-hosted agent, by specifying both a vmImage
and a Pool
variable, like the following example. For the hosted agent, specify Azure Pipelines
as the pool name, and for self-hosted agents, leave the vmImage
blank. The blank vmImage
for the self-hosted agent may result in some unusual entries in the logs but they won't affect the pipeline.
strategy:
matrix:
microsofthosted:
poolName: Azure Pipelines
vmImage: ubuntu-latest
selfhosted:
poolName: FabrikamPool
vmImage:
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- script: echo test
jobs:
- job: Build
strategy:
matrix:
Python35:
PYTHON_VERSION: '3.5'
Python36:
PYTHON_VERSION: '3.6'
Python37:
PYTHON_VERSION: '3.7'
maxParallel: 2
This matrix creates three jobs: "Build Python35," "Build Python36," and "Build Python37." Within each job, a variable named PYTHON_VERSION is available. In "Build Python35," the variable is set to "3.5". It's likewise set to "3.6" in "Build Python36." Only two jobs run simultaneously.
:::moniker range=">=azure-pipelines-2019"
The parallel job strategy specifies how many duplicates of a job should run.
strategy:
parallel: string # Run the job this many times.
parallel
string.
Run the job this many times.
:::moniker-end
The parallel job strategy is useful for slicing up a large test matrix. The Visual Studio Test task understands how to divide the test load across the number of scheduled jobs.
jobs:
- job: SliceItFourWays
strategy:
parallel: 4