diff --git a/eng/common/pipelines/templates/steps/sparse-checkout.yml b/eng/common/pipelines/templates/steps/sparse-checkout.yml index 50603bc35a24..5b36bf48e4a9 100644 --- a/eng/common/pipelines/templates/steps/sparse-checkout.yml +++ b/eng/common/pipelines/templates/steps/sparse-checkout.yml @@ -25,8 +25,6 @@ steps: script: | function SparseCheckout([Array]$paths, [Hashtable]$repository) { - $paths = $paths -Join ' ' - $dir = $repository.WorkingDirectory if (!$dir) { $dir = "./$($repository.Name)" @@ -50,7 +48,9 @@ steps: git sparse-checkout set '/*' '!/*/' '/eng' } - $gitsparsecmd = "git sparse-checkout add $paths" + # Prevent wildcard expansion in Invoke-Expression (e.g. for checkout path '/*') + $quotedPaths = $paths | ForEach-Object { "'$_'" } + $gitsparsecmd = "git sparse-checkout add $quotedPaths" Write-Host $gitsparsecmd Invoke-Expression -Command $gitsparsecmd