diff --git a/eng/common/scripts/New-RegenerateMatrix.ps1 b/eng/common/scripts/New-RegenerateMatrix.ps1 index 63d1f228e101..c876ed1f64e2 100644 --- a/eng/common/scripts/New-RegenerateMatrix.ps1 +++ b/eng/common/scripts/New-RegenerateMatrix.ps1 @@ -6,11 +6,15 @@ param ( [Parameter()] [string]$OutputVariableName, + # Both counts are used as divisors when splitting the items, so reject zero and + # negative values here rather than failing later with a divide-by-zero. [Parameter()] + [ValidateRange(1, [int]::MaxValue)] [int]$JobCount = 8, # The minimum number of items per job. If the number of items is less than this, then the number of jobs will be reduced. [Parameter()] + [ValidateRange(1, [int]::MaxValue)] [int]$MinimumPerJob = 10, [Parameter()] @@ -40,7 +44,11 @@ function Split-Items([array]$Items) { } $itemsPerGroup = [math]::Floor($itemCount / $JobCount) - $largeJobCount = $itemCount % $itemsPerGroup + # The remainder has to be taken over the number of groups, not the size of a group. + # Taking it over $itemsPerGroup produces too few large groups whenever + # $itemCount % $itemsPerGroup -lt $itemCount % $JobCount, and the trailing items are + # then silently dropped from the matrix. + $largeJobCount = $itemCount % $JobCount $groups = [object[]]::new($JobCount) $i = 0