在 Azure Pipelines PublishSymbols 任务中,如何使用变量作为 searchPattern 参数?
In the Azure Pipelines PublishSymbols task, how can I use a variable as the searchPattern parameter?
跟进我的 :
@leo-liu-msft 的解决方案非常适合显式列出要包含在 searchPattern
.
中的文件
我想动态生成搜索模式,所以我在 PublishSymbols@2
之前的步骤中 运行 一个 PowerShell 脚本。这将创建一个字符串对象,其中包含所有 PDB 文件及其关联的 DLL 和 EXE,由 Windows 换行符分隔。该字符串保存在一个变量(不是输出变量)中,该变量用作 PublishSymbols@2
任务中 searchPattern
的参数。
- 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
问题是 PublishSymbols@2
只读取和处理 $(searchPattern)
变量的第一行。
我最初尝试 searchPattern: $(searchPattern)
,全部都在一条线上,但那没有用,所以我改用管道。还是不行。
这个问题可能是因为Azure DevOps不支持multi-line变量,所以当你从PowerShell输出一个multi-line变量到Azure DevOps变量时,multi-line数据被消除了。
为避免这种情况,您可以使用%0D%0A
作为分隔符来分隔多行数据:
$enter = "%0D%0A"
...
$searchPattern += $ado
$searchPattern += $enter
...
跟进我的
@leo-liu-msft 的解决方案非常适合显式列出要包含在 searchPattern
.
我想动态生成搜索模式,所以我在 PublishSymbols@2
之前的步骤中 运行 一个 PowerShell 脚本。这将创建一个字符串对象,其中包含所有 PDB 文件及其关联的 DLL 和 EXE,由 Windows 换行符分隔。该字符串保存在一个变量(不是输出变量)中,该变量用作 PublishSymbols@2
任务中 searchPattern
的参数。
- 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
问题是 PublishSymbols@2
只读取和处理 $(searchPattern)
变量的第一行。
我最初尝试 searchPattern: $(searchPattern)
,全部都在一条线上,但那没有用,所以我改用管道。还是不行。
这个问题可能是因为Azure DevOps不支持multi-line变量,所以当你从PowerShell输出一个multi-line变量到Azure DevOps变量时,multi-line数据被消除了。
为避免这种情况,您可以使用%0D%0A
作为分隔符来分隔多行数据:
$enter = "%0D%0A"
...
$searchPattern += $ado
$searchPattern += $enter
...