【问题标题】:TFS build write message to summaryTFS 构建将消息写入摘要
【发布时间】:2019-09-16 08:16:38
【问题描述】:

我想在构建摘要中添加一条消息(链接)(也可以是新部分,没关系):

基于此: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;]" 

但是我收到一条错误消息:

无法处理命令'##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]' 成功地。请参考文档 (http://go.microsoft.com/fwlink/?LinkId=817296) 无法上传任务 附件文件,未指定附件文件位置或 磁盘上不存在附件文件

如何在构建摘要中添加文本/链接/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 ##[错误]无法处理命令 '##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]hellomessage' 成功地。请参考文档 (http://go.microsoft.com/fwlink/?LinkId=817296) 2019-04-27T01:49:01.1516289Z ##[错误]无法上传任务附件 文件,未指定附件文件位置或未指定附件文件 存在于磁盘上

编辑 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

【问题讨论】:

  • 您好像错过了Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=ObjectSharp;]*$Tempfile*" 的消息
  • 试过了。没用
  • 我已经尝试了您提供的示例,它对我有用。你能提供更多信息吗?可能是错误和代码的屏幕截图。
  • 请参阅编辑

标签: tfs msbuild azure-devops tfsbuild


【解决方案1】:

“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.uploadsuammrytask.addattachment type=Distributedtask.Core.Summary 的简写。

【讨论】:

  • 我仍然遇到同样的错误:无法成功处理命令 '##vso[task.uplaodsummary]C:\Builds\tfsbuilddev03\Agent1\6\s\'。请参考文档 (go.microsoft.com/fwlink/?LinkId=817296) ##vso[task.uplaodsummary] 不是任务命令扩展的公认命令。请参考文档 (go.microsoft.com/fwlink/?LinkId=817296)
  • 您检查文件路径是否正确?你能打印路径变量并在这里分享吗?
  • 我尝试了一个简单的文本。只是为了确认这应该有效吗?:Write-Host "##vso[task.uplaodsummary]test123"
  • 正如我在回答的第一行所说的,你不能放简单的文字,你必须给一个文件。
  • 作品:)。写入主机“##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Report;]$path”,文件必须存在,否则我收到错误消息
猜你喜欢
  • 2020-01-05
  • 2021-09-25
  • 1970-01-01
  • 2019-09-18
  • 2012-03-04
  • 1970-01-01
  • 2020-04-25
  • 2017-12-04
  • 1970-01-01
相关资源
最近更新 更多