Skip to content

Commit ee4f485

Browse files
authored
Skip env processing on matrix import step (#7854)
1 parent bdd5f99 commit ee4f485

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

eng/common-tests/matrix-generator/tests/job-matrix-functions.modification.tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ Describe "Platform Matrix Import" -Tag "import" {
388388
{ GenerateMatrix $importConfig "sparse" } | Should -Throw
389389
}
390390

391+
It "Should process filters against env references in imported matrix in the correct order" {
392+
$matrixJson = @'
393+
{
394+
"matrix": {
395+
"$IMPORT": "./matrix-generator/tests/test-import-matrix-env.json",
396+
"BarEnv": "env:BAR"
397+
}
398+
}
399+
'@
400+
401+
[System.Environment]::SetEnvironmentVariable("FOO", "Value1")
402+
[System.Environment]::SetEnvironmentVariable("BAR", "Value2")
403+
$importConfig = GetMatrixConfigFromJson $matrixJson
404+
[array]$matrix = GenerateMatrix $importConfig "sparse" -filter @("FooEnv=.*FOO.*")
405+
406+
$matrix[0].name | Should -Be Value2_Value1
407+
}
391408
}
392409

393410
Describe "Platform Matrix Replace" -Tag "UnitTest", "replace" {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"matrix": {
3+
"FooEnv": "env:FOO"
4+
}
5+
}

eng/common/scripts/job-matrix/job-matrix-functions.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ function GenerateMatrix(
9696
[String]$displayNameFilter = ".*",
9797
[Array]$filters = @(),
9898
[Array]$replace = @(),
99-
[Array]$nonSparseParameters = @()
99+
[Array]$nonSparseParameters = @(),
100+
[Switch]$skipEnvironmentVariables
100101
) {
101102
$matrixParameters, $importedMatrix, $combinedDisplayNameLookup = `
102103
ProcessImport $config.matrixParameters $selectFromMatrixType $nonSparseParameters $config.displayNamesLookup
@@ -124,7 +125,9 @@ function GenerateMatrix(
124125

125126
$matrix = FilterMatrix $matrix $filters
126127
$matrix = ProcessReplace $matrix $replace $combinedDisplayNameLookup
127-
$matrix = ProcessEnvironmentVariableReferences $matrix $combinedDisplayNameLookup
128+
if (!$skipEnvironmentVariables) {
129+
$matrix = ProcessEnvironmentVariableReferences $matrix $combinedDisplayNameLookup
130+
}
128131
$matrix = FilterMatrixDisplayName $matrix $displayNameFilter
129132
return $matrix
130133
}
@@ -427,10 +430,14 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
427430
exit 1
428431
}
429432
$importedMatrixConfig = GetMatrixConfigFromFile (Get-Content -Raw $importPath)
433+
# Add skipEnvironmentVariables so we don't process environment variables on import
434+
# because we want top level filters to work against the the env key, not the value.
435+
# The environment variables will get resolved after the import.
430436
$importedMatrix = GenerateMatrix `
431437
-config $importedMatrixConfig `
432438
-selectFromMatrixType $selection `
433-
-nonSparseParameters $nonSparseParameters
439+
-nonSparseParameters $nonSparseParameters `
440+
-skipEnvironmentVariables
434441

435442
$combinedDisplayNameLookup = $importedMatrixConfig.displayNamesLookup
436443
foreach ($lookup in $displayNamesLookup.GetEnumerator()) {

0 commit comments

Comments
 (0)