TFS 构建将消息写入摘要

标签 tfs msbuild azure-devops tfsbuild

我想在构建摘要中添加一条消息(链接)(也可以是一个新部分,并不重要):

enter image description here

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

enter image description here

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

enter image description here

enter image description here

最佳答案

“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 的缩写.

关于TFS 构建将消息写入摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55873998/

相关文章:

c# - 使用 Visual Studio Team Services 进行自动化用户界面测试

azure - 等待新部署的应用服务在 Azure Devops 发布管道中重新启动

c# - 禁用 TFS 结帐唠叨

tfs - 如何成功连接到 TFS 2010 工作项存储?

c# - .tfignore 不是忽略文件

MSbuild 属性

tfs - 执行 TFS 构建时,MSBuild 不一致地失败(通常是错误 C1093/存储空间不足)

collections - 组织项目集合和团队项目的建议

asp.net - 如何使用某些发布配置文件从命令行发布站点?

visual-studio - 管理持续部署到 Azure 网站的源代码控制应用程序中的连接字符串