问题
I want to write string message to TFS build summary. I have a Powershell task with variable
$output = $(Build.SourcesDirectory)\scripts\SCRIPT_NAME.ps1
$output
that holds
=====
Numb. of files for patch in:
Win32 = 2
Win64 = 123
---
Numb. of original files:
Win32 = 0
Win64 = 12
=====
that scheme is a whole message, now I just want to display it in a place that picture below points or in any other section as long as it is in "Summary" I took a look on this Stack question but it answers how to display hyperlink to file. I want to specifically display string not a link to file that holds what I want to print. Additionally I referred to Microsoft docs but I haven't found what I'm looking for
回答1:
The simple way is just using Logging Commands as your shared link suggested:
##vso[task.uploadsummary]local file path
Upload and attach summary markdown to current timeline record. This summary shall be added to the build/release summary and not available for download with logs.
This will not generate hyperlink in summary, it will directly list the text/content in the shared file on build Summary page. You just need to put the output in a file, then use above command lin.
For example:
- Add PowerShell task
Script:
Write-Host "##vso[task.uploadsummary]c:\testsummary.md"
Besides, you could also create your own extension to display graphical content in my Azure DevOps build summary page. (Too complicated, not recommend)
For example add a custom section in build result through your extension, with this way, you can add html test results report in that custom section. There is the sample about build result extension: vsts-extension-samples
More information about how to build extension, you can refer to this article
Create your first extension for Visual Studio Team Services
A extension for your reference Publish HTML Artifact
Update
In md files for Markdown format you could use </br>
to wrap next line. Start a line with a hash character #
to set a heading. For example
=====</br>Processed files statistics </br>Numb. of files for patch in: Win32 = 2 [this is single line]</br> #Win64 = 123 [this is header] </br>[here split to lines rest of report]</br>=====
Then the result format of report you could check right part:
回答2:
Partial/temporary solution
As this is currently closest solution to 100% correctly answer question this is accepted answer. Question will be updated when better solution is implemented and pointed by somebody here
As at the moment I need quick solution I display content of $output
using task.logissue type=warning
. As just using Write-Host "##vso[task.logissue type=warning;]$output"
will display content of $output
in one line I'm splitting it on new line and iterating through array
$output = $output.Split("`n`r")
foreach($line in $output){
Write-Host "##vso[task.logissue type=warning;]$line"
}
That produces expected output
Edit.: With described solution I'm partially answering my question - I'm displaying Warning but I want to display only information. Not marked as Error or Warning
来源:https://stackoverflow.com/questions/57756389/tfs-write-string-message-to-build-summary