Skip to content

Commit c5cb9a2

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 1429 (Azure#16826)
* Add job matrix generation scripts * Add working job matrix example pipeline and common matrix generation pipeline. * Update job matrix tests path * Parameterize matrix generation job path * Add global variable to override nuget security checks to sample matrix pipeline * Update readme matrix pipeline example to match sample file Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
1 parent 622b1e8 commit c5cb9a2

File tree

11 files changed

+2094
-0
lines changed

11 files changed

+2094
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
parameters:
2+
- name: AdditionalParameters
3+
type: object
4+
- name: CloudConfig
5+
type: object
6+
default: {}
7+
- name: MatrixConfigs
8+
type: object
9+
default: []
10+
- name: MatrixFilters
11+
type: object
12+
default: []
13+
- name: JobTemplatePath
14+
type: string
15+
16+
jobs:
17+
- job: generate_matrix
18+
variables:
19+
displayNameFilter: $[ coalesce(variables.jobMatrixFilter, '.*') ]
20+
pool:
21+
name: Azure Pipelines
22+
vmImage: ubuntu-18.04
23+
displayName: Generate Job Matrix
24+
steps:
25+
- ${{ each config in parameters.MatrixConfigs }}:
26+
- ${{ if eq(config.GenerateVMJobs, 'true') }}:
27+
- task: Powershell@2
28+
inputs:
29+
pwsh: true
30+
filePath: eng/common/scripts/job-matrix/Create-JobMatrix.ps1
31+
arguments: >
32+
-ConfigPath ${{ config.Path }}
33+
-Selection ${{ config.Selection }}
34+
-DisplayNameFilter "$(displayNameFilter)"
35+
-Filters "${{ join('","', parameters.MatrixFilters) }}","container=^$","SupportedClouds=^$|${{ parameters.CloudConfig.Cloud }}"
36+
-NonSparseParameters "${{ join('","', config.NonSparseParameters) }}"
37+
displayName: Generate VM Job Matrix ${{ config.Name }}
38+
name: generate_vm_job_matrix_${{ config.Name }}
39+
40+
- ${{ if eq(config.GenerateContainerJobs, 'true') }}:
41+
- task: Powershell@2
42+
inputs:
43+
pwsh: true
44+
filePath: eng/common/scripts/job-matrix/Create-JobMatrix.ps1
45+
arguments: >
46+
-ConfigPath ${{ config.Path }}
47+
-Selection ${{ config.Selection }}
48+
-DisplayNameFilter "$(displayNameFilter)"
49+
-Filters "${{ join('","', parameters.MatrixFilters) }}", "container=.*", "SupportedClouds=^$|${{ parameters.CloudConfig.Cloud }}"
50+
-NonSparseParameters "${{ join('","', config.NonSparseParameters) }}"
51+
displayName: Generate Container Job Matrix
52+
name: generate_container_job_matrix_${{ config.Name }}
53+
54+
- ${{ each config in parameters.MatrixConfigs }}:
55+
- ${{ if eq(config.GenerateVMJobs, 'true') }}:
56+
- template: ${{ parameters.JobTemplatePath }}
57+
parameters:
58+
UsePlatformContainer: false
59+
Matrix: dependencies.generate_matrix.outputs['generate_vm_job_matrix_${{ config.Name }}.matrix']
60+
DependsOn: generate_matrix
61+
CloudConfig: ${{ parameters.CloudConfig }}
62+
${{ each param in parameters.AdditionalParameters }}:
63+
${{ param.key }}: ${{ param.value }}
64+
65+
- ${{ if eq(config.GenerateContainerJobs, 'true') }}:
66+
- template: ${{ parameters.JobTemplatePath }}
67+
parameters:
68+
UsePlatformContainer: true
69+
Matrix: dependencies.generate_matrix.outputs['generate_container_job_matrix_${{ config.Name }}.matrix']
70+
DependsOn: generate_matrix
71+
CloudConfig: ${{ parameters.CloudConfig }}
72+
${{ each param in parameters.AdditionalParameters }}:
73+
${{ param.key }}: ${{ param.value }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<#
2+
.SYNOPSIS
3+
Generates a JSON object representing an Azure Pipelines Job Matrix.
4+
See https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#parallelexec
5+
6+
.EXAMPLE
7+
./eng/common/scripts/Create-JobMatrix $context
8+
#>
9+
10+
[CmdletBinding()]
11+
param (
12+
[Parameter(Mandatory=$True)][string] $ConfigPath,
13+
[Parameter(Mandatory=$True)][string] $Selection,
14+
[Parameter(Mandatory=$False)][string] $DisplayNameFilter,
15+
[Parameter(Mandatory=$False)][array] $Filters,
16+
[Parameter(Mandatory=$False)][array] $NonSparseParameters
17+
)
18+
19+
. $PSScriptRoot/job-matrix-functions.ps1
20+
21+
$config = GetMatrixConfigFromJson (Get-Content $ConfigPath)
22+
# Strip empty string filters in order to be able to use azure pipelines yaml join()
23+
$Filters = $Filters | Where-Object { $_ }
24+
25+
[array]$matrix = GenerateMatrix `
26+
-config $config `
27+
-selectFromMatrixType $Selection `
28+
-displayNameFilter $DisplayNameFilter `
29+
-filters $Filters `
30+
-nonSparseParameters $NonSparseParameters
31+
32+
$serialized = SerializePipelineMatrix $matrix
33+
34+
Write-Output $serialized.pretty
35+
Write-Output "##vso[task.setVariable variable=matrix;isOutput=true]$($serialized.compressed)"

0 commit comments

Comments
 (0)