Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ Describe "Platform Matrix Import" -Tag "import" {
{ GenerateMatrix $importConfig "sparse" } | Should -Throw
}

It "Should process filters against env references in imported matrix in the correct order" {
$matrixJson = @'
{
"matrix": {
"$IMPORT": "./matrix-generator/tests/test-import-matrix-env.json",
"BarEnv": "env:BAR"
}
}
'@

[System.Environment]::SetEnvironmentVariable("FOO", "Value1")
[System.Environment]::SetEnvironmentVariable("BAR", "Value2")
$importConfig = GetMatrixConfigFromJson $matrixJson
[array]$matrix = GenerateMatrix $importConfig "sparse" -filter @("FooEnv=.*FOO.*")

$matrix[0].name | Should -Be Value2_Value1
}
}

Describe "Platform Matrix Replace" -Tag "UnitTest", "replace" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"matrix": {
"FooEnv": "env:FOO"
}
}
13 changes: 10 additions & 3 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function GenerateMatrix(
[String]$displayNameFilter = ".*",
[Array]$filters = @(),
[Array]$replace = @(),
[Array]$nonSparseParameters = @()
[Array]$nonSparseParameters = @(),
[Switch]$skipEnvironmentVariables
) {
$matrixParameters, $importedMatrix, $combinedDisplayNameLookup = `
ProcessImport $config.matrixParameters $selectFromMatrixType $nonSparseParameters $config.displayNamesLookup
Expand Down Expand Up @@ -124,7 +125,9 @@ function GenerateMatrix(

$matrix = FilterMatrix $matrix $filters
$matrix = ProcessReplace $matrix $replace $combinedDisplayNameLookup
$matrix = ProcessEnvironmentVariableReferences $matrix $combinedDisplayNameLookup
if (!$skipEnvironmentVariables) {
$matrix = ProcessEnvironmentVariableReferences $matrix $combinedDisplayNameLookup
}
$matrix = FilterMatrixDisplayName $matrix $displayNameFilter
return $matrix
}
Expand Down Expand Up @@ -427,10 +430,14 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Array]$n
exit 1
}
$importedMatrixConfig = GetMatrixConfigFromFile (Get-Content -Raw $importPath)
# Add skipEnvironmentVariables so we don't process environment variables on import
# because we want top level filters to work against the the env key, not the value.
# The environment variables will get resolved after the import.
$importedMatrix = GenerateMatrix `
-config $importedMatrixConfig `
-selectFromMatrixType $selection `
-nonSparseParameters $nonSparseParameters
-nonSparseParameters $nonSparseParameters `
-skipEnvironmentVariables

$combinedDisplayNameLookup = $importedMatrixConfig.displayNamesLookup
foreach ($lookup in $displayNamesLookup.GetEnumerator()) {
Expand Down