Following up on my previous question:
@leo-liu-msft's solution worked well for explicitly listing the files to be included in searchPattern
.
I want to generate the search pattern dynamically, so I run a PowerShell script in the step before PublishSymbols@2
. This creates a string object with all of the PDB files, and their associated DLLs and EXEs, separated by Windows newlines. The string is saved in a variable (not an output variable), which is used as the argument for searchPattern
in the PublishSymbols@2
task.
- powershell: |
[xml]$project = Get-Content $(Pipeline.Workspace)/s/Build/abc_components.targets
$componentCount = 0
$databaseCount = 0
$searchPattern = @()
$project.Project.ItemGroup.Component | ForEach-Object {
$componentName = $_.Include
$database = $_.Database # This is the PDB filename
$outputFile = $_.OutputFile # This is the EXE or DLL filename
if (($componentName -like "abc*") -or ($componentName -like "xyz*")) {
$componentCount += 1
if(($database -ne "") -and ($database -match $componentName)) {
$databaseCount += 1
$ado = Edit-ResourceName $database #Edit-ResourceName is a function that edits the path
$searchPattern += $ado
$ado2 = Edit-ResourceName $outputFile #Edit-ResourceName is a function that edits the path
$searchPattern += $ado2
}
}
}
Write-Output "Number of components: " $componentCount
Write-Output "Number of databases: " $databaseCount
Write-Output "searchPattern length: " $searchPattern.Length
$searchPattern = $searchPattern | Out-String
Write-Output $searchPattern
echo "##vso[task.setvariable variable=searchPattern]$searchPattern"
enabled: true
displayName: Generate searchPattern for symbol table
- task: PublishSymbols@2
inputs:
symbolsFolder: $(Pipeline.Workspace)/s
searchPattern: |
$(searchPattern)
indexSources: false
publishSymbols: true
symbolServerType: TeamServices
symbolsProduct: "ABC"
symbolsVersion: $(major).$(minor).$(revision)
symbolsArtifactName: "Symbols_ABC.$(major).$(minor).$(revision)_$(buildConfiguration)"
enabled: true
condition: eq(variables['doPublishSymbols'], 'true')
displayName: Create symbol table
The problem is that PublishSymbols@2
only reads and processes the first line of the $(searchPattern)
variable.
I had originally tried searchPattern: $(searchPattern)
, all on one line, but that didn't work so I tried the pipe instead. Still didn't work.
This issue probably occurs because Azure DevOps does not support multi-line variables, so when you output a multi-line variable from PowerShell to Azure DevOps variable, the multi-line data is eliminated.
To avoid this, you can use %0D%0A
as a delimiter to separate multiple lines of data:
$enter = "%0D%0A"
...
$searchPattern += $ado
$searchPattern += $enter
...