我想在构建摘要中添加一条消息(链接)(也可以是一个新部分,并不重要):
基于此:https://blogs.objectsharp.com/post/2017/04/25/Writing-to-the-Build-Report-in-TFS-2015.aspx ,
我在我的 Powershell 脚本中添加了这一行:
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]"
但是我收到一条错误消息:
Unable to process command '##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296) Cannot upload task attachment file, attachment file location is not specified or attachment file not exist on disk
如何在构建摘要中添加文本/链接/href? (powershell 还是其他方法?)
编辑: 请参阅下面的编辑。我在构建步骤中从 PowerShell 运行此脚本:
$path = $sourcesFolder + "file:///C:/Temp/dotCover-xunit.html"
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]$path"
编辑2:(尝试了一个简单的文本)
function AddSummaryMessage{
$filePath = "somestring"
Write-Host "##vso[task.uplaodsummary]$filePath"
}
还尝试使用“hellomessage”作为字符串:
错误消息:
2019-04-27T01:49:01.1513980Z ##[error]Unable to process command '##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]hellomessage' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296) 2019-04-27T01:49:01.1516289Z ##[error]Cannot upload task attachment file, attachment file location is not specified or attachment file not exist on disk
编辑3:
function AddSummaryMessage{
$file = Get-ChildItem $outputFolder -name "dotcover.html";
if ($file){
LogMessage("Found dotcover report file: " + ($outputFolder + $file))
$path = ($outputFolder + $file)
Write-Host "##vso[task.uplaodsummary]$path"
}
}
OUTPUT:
9:27:01 AM add summary message
9:27:01 AM Found dotcover report file: C:\Builds\tfsbuilddev02\Agent1\110\s\dotCover\dotcover.html
最佳答案
“hellomessage”无法工作,因为您必须提供文件路径而不仅仅是字符串。
在尝试使用 PowerShell 脚本时,文件路径出现问题。
我不知道 sourcesFolder
的值是多少我不明白 + file ...
是什么? .
我尝试以这种方式连接文件路径:
$filePath = $(Build.SourcesDirectory)\test.html
# Verify the path is correct:
Write-Host $filePath
# Output: D:\a\1\s\test.html
我通过以下方式将文件上传到“摘要”页面:
Write-Host "##vso[task.uplaodsummary]$filePath"
上传成功,显示test.html
存在于构建摘要页面中。
因此,在您的情况下,您必须检查文件路径并修复它,之后上传将起作用(您也可以尝试放置硬编码路径并检查它是否有效)。
P.S - task.uploadsuammry
是 task.addattachment type=Distributedtask.Core.Summary
的缩写.
关于TFS 构建将消息写入摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55873998/