jobs.job.strategy 定義
此作業的執行策略。
實作
實施 | 說明 |
---|---|
策略:矩陣、maxParallel | 矩陣作業策略。 |
策略:平行 | 平行作業策略。 |
備註
若要從後續作業中的作業存取變數,請參閱 設定多作業輸出變數。
策略:矩陣、maxParallel
使用矩陣會產生作業的複本,每個複本都有不同的輸入。 這些複本適用於針對不同的組態或平臺版本進行測試。
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 }。
定義作業策略的矩陣;請參閱下列範例。
maxParallel
字串。
平行執行的作業數目上限。
備註
strategy:
matrix: { string1: { string2: string3 } }
maxParallel: number
針對矩陣中每個出現的 string1,會產生作業的複本。 string1 的名稱是複本的名稱,並附加至作業的名稱。 針對每個 string2,作業可以使用值 string3string2 變數。
備註
矩陣組態名稱只能包含基本的拉丁字母(A-Z 和 a-z)、數位(0-9)和底線(_
)。
這些名稱必須以字母開頭。
此外,其長度必須是 100 個字元或更少。
選擇性 maxParallel
關鍵詞會指定要同時執行的矩陣腿數目上限。
如果未指定 maxParallel
或設定為 0,則不會套用任何限制。
範例
在多個平臺上建置
此範例會使用 matrix
作業策略,在多個平臺上建置。
# 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
此管線會使用 腳本 在每個平臺的整數腳本解釋器中執行:macOS 和 Linux 上的 Bash、Windows 上的 CMD。 若要深入瞭解,請參閱 多平臺腳本。
使用自我裝載和Microsoft裝載的代理程式,在多個平臺上建置
下列範例會藉由同時指定 vmImage
和 Pool
變數,以建置在自我裝載代理程式和Microsoft裝載的代理程式上,如下列範例所示。 針對裝載的代理程式,請將 Azure Pipelines
指定為集區名稱,針對自我裝載式代理程式則將 vmImage
保留為空白。 自我裝載代理程式的空白 vmImage
可能會導致記錄檔中有一些不尋常的專案,但不會影響管線。
strategy:
matrix:
microsofthosted:
poolName: Azure Pipelines
vmImage: ubuntu-latest
selfhosted:
poolName: FabrikamPool
vmImage:
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- script: echo test
使用不同的 Python 版本建置
jobs:
- job: Build
strategy:
matrix:
Python35:
PYTHON_VERSION: '3.5'
Python36:
PYTHON_VERSION: '3.6'
Python37:
PYTHON_VERSION: '3.7'
maxParallel: 2
此矩陣會建立三個作業:「建置 Python35」、「建置 Python36」和「建置 Python37」。在每個作業中,有一個名為 PYTHON_VERSION的變數可供使用。 在 “Build Python35” 中,變數會設定為 “3.5”。 它同樣設定為 「Build Python36」 中的 「3.6」。。只有兩個作業同時執行。
策略:平行
平行作業策略會指定應該執行的作業複本數目。
strategy:
parallel: string # Run the job this many times.
性能
parallel
字串。
多次執行作業。
備註
平行作業策略適用於分割大型測試矩陣。 Visual Studio 測試工作 瞭解如何將測試負載分割到排程工作的數目。
範例
jobs:
- job: SliceItFourWays
strategy:
parallel: 4