Skip to content

Commit 2fec622

Browse files
azure-sdkscbedd
andauthored
Sync eng/common directory with azure-sdk-tools for PR 10145 (#2400)
* support accessing a different key for the value of the Package during batching in Create-PrJobMatrix --------- Co-authored-by: Scott Beddall <[email protected]>
1 parent 9c9a720 commit 2fec622

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

eng/common/pipelines/templates/jobs/generate-job-matrix.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ parameters:
4545
- name: EnablePRGeneration
4646
type: boolean
4747
default: false
48+
# name of the variable that will be added when creating batches for the PR Job Matrix
4849
- name: PRMatrixSetting
4950
type: string
5051
default: 'ArtifactPackageNames'
52+
# name of the key in PackageInfo that will be used to get the identifier when generating matrix batches
53+
- name: PRMatrixKey
54+
type: string
55+
default: 'ArtifactName'
5156
- name: PRJobBatchSize
5257
type: number
5358
default: 10
@@ -141,6 +146,7 @@ jobs:
141146
-PackagePropertiesFolder $(Build.ArtifactStagingDirectory)/PackageInfo `
142147
-PRMatrixFile matrix.json `
143148
-PRMatrixSetting ${{ parameters.PRMatrixSetting }} `
149+
-PRMatrixKey ${{ parameters.PRMatrixKey }} `
144150
-DisplayNameFilter '$(displayNameFilter)' `
145151
-Filters '${{ join(''',''', parameters.MatrixFilters) }}', 'container=^$', 'SupportedClouds=^$|${{ parameters.CloudConfig.Cloud }}', 'Pool=${{ pool.filter }}' `
146152
-IndirectFilters '${{ join(''',''', parameters.PRMatrixIndirectFilters) }}' `

eng/common/scripts/job-matrix/Create-PrJobMatrix.ps1

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ param (
4040
[Parameter(Mandatory = $true)][string] $PackagePropertiesFolder,
4141
[Parameter(Mandatory = $true)][string] $PRMatrixFile,
4242
[Parameter(Mandatory = $true)][string] $PRMatrixSetting,
43-
[Parameter(Mandatory = $False)][string] $DisplayNameFilter,
44-
[Parameter(Mandatory = $False)][array] $Filters,
45-
[Parameter(Mandatory = $False)][array] $IndirectFilters,
46-
[Parameter(Mandatory = $False)][array] $Replace,
47-
[Parameter(Mandatory = $False)][bool] $SparseIndirect = $true,
48-
[Parameter(Mandatory = $False)][int] $PackagesPerPRJob = 10,
43+
[Parameter(Mandatory = $false)][string] $DisplayNameFilter,
44+
[Parameter(Mandatory = $false)][array] $Filters,
45+
[Parameter(Mandatory = $false)][array] $IndirectFilters,
46+
[Parameter(Mandatory = $false)][array] $Replace,
47+
[Parameter(Mandatory = $false)][string] $PRMatrixKey = "ArtifactName",
48+
[Parameter(Mandatory = $false)][bool] $SparseIndirect = $true,
49+
[Parameter(Mandatory = $false)][int] $PackagesPerPRJob = 10,
4950
[Parameter()][switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID)
5051
)
5152

@@ -74,6 +75,7 @@ function QueuePop([ref]$queue) {
7475
function GeneratePRMatrixForBatch {
7576
param (
7677
[Parameter(Mandatory = $true)][array] $Packages,
78+
[Parameter(Mandatory = $true)][array] $MatrixKey,
7779
[Parameter(Mandatory = $false)][bool] $FullSparseMatrix = $false
7880
)
7981

@@ -104,7 +106,7 @@ function GeneratePRMatrixForBatch {
104106
$matrixResults = @()
105107

106108
if (!$matrixConfig) {
107-
Write-Error "Unable to find matrix config for $matrixBatchKey. Check the package properties for the package $($matrixBatch[0].ArtifactName)."
109+
Write-Error "Unable to find matrix config for $matrixBatchKey. Check the package properties for the package $($matrixBatch[0].($MatrixKey))."
108110
exit 1
109111
}
110112

@@ -166,7 +168,7 @@ function GeneratePRMatrixForBatch {
166168
$batchCounter = 1
167169

168170
foreach ($batch in $packageBatches) {
169-
$namesForBatch = ($batch | ForEach-Object { $_.ArtifactName }) -join ","
171+
$namesForBatch = ($batch | ForEach-Object { $_.($MatrixKey) }) -join ","
170172

171173
foreach ($matrixOutputItem in $matrixResults) {
172174
# we need to clone this, as each item is an object with possible children
@@ -195,7 +197,7 @@ function GeneratePRMatrixForBatch {
195197
$batchSuffixNecessary = $packageBatches.Length -gt 0
196198
$batchCounter = 1
197199
foreach ($batch in $packageBatches) {
198-
$namesForBatch = ($batch | ForEach-Object { $_.ArtifactName }) -join ","
200+
$namesForBatch = ($batch | ForEach-Object { $_.($MatrixKey) }) -join ","
199201
$outputItem = QueuePop -queue ([ref]$matrixResults)
200202

201203
$outputItem["parameters"]["$PRMatrixSetting"] = $namesForBatch
@@ -228,7 +230,7 @@ if (!(Test-Path $PRMatrixFile)) {
228230
exit 1
229231
}
230232

231-
Write-Host "Generating PR job matrix for $PackagePropertiesFolder"
233+
Write-Host "Generating PR job matrix for $PackagePropertiesFolder using accesskey $PRMatrixKey to determine artifact batches."
232234

233235
$configs = Get-Content -Raw $PRMatrixFile | ConvertFrom-Json
234236

@@ -251,16 +253,16 @@ $OverallResult = @()
251253
if ($directPackages) {
252254
Write-Host "Discovered $($directPackages.Length) direct packages"
253255
foreach($artifact in $directPackages) {
254-
Write-Host "-> $($artifact.ArtifactName)"
256+
Write-Host "-> $($artifact.($PRMatrixKey))"
255257
}
256-
$OverallResult += (GeneratePRMatrixForBatch -Packages $directPackages) ?? @()
258+
$OverallResult += (GeneratePRMatrixForBatch -Packages $directPackages -MatrixKey $PRMatrixKey) ?? @()
257259
}
258260
if ($indirectPackages) {
259261
Write-Host "Discovered $($indirectPackages.Length) indirect packages"
260262
foreach($artifact in $indirectPackages) {
261-
Write-Host "-> $($artifact.ArtifactName)"
263+
Write-Host "-> $($artifact.($PRMatrixKey))"
262264
}
263-
$OverallResult += (GeneratePRMatrixForBatch -Packages $indirectPackages -FullSparseMatrix (-not $SparseIndirect)) ?? @()
265+
$OverallResult += (GeneratePRMatrixForBatch -Packages $indirectPackages -MatrixKey $PRMatrixKey -FullSparseMatrix (-not $SparseIndirect)) ?? @()
264266
}
265267
$serialized = SerializePipelineMatrix $OverallResult
266268

0 commit comments

Comments
 (0)