TFS build write message to summary

我是研究僧i 提交于 2019-12-11 17:12:13

问题


I want add a message (link) in the build summary (can be a new section also, doesn't really matter):

Based on this: https://blogs.objectsharp.com/post/2017/04/25/Writing-to-the-Build-Report-in-TFS-2015.aspx,

I've added this line in my Powershell script:

Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]" 

However I get an error message:

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

How would one add a text/link/href in the summary of the build? (powershell or other method?)

EDIT: Please see edit below. I run this script from PowerShell during the build step:

$path = $sourcesFolder + "file:///C:/Temp/dotCover-xunit.html"
Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=DotCover Results;]$path"

EDIT 2: (tried a simple text)

function AddSummaryMessage{
	$filePath = "somestring"
	Write-Host "##vso[task.uplaodsummary]$filePath"
}

also tried with "hellomessage" as string in there:

Error message:

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

EDIT 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


回答1:


The "hellomessage" can't work because you must give a file path and not just a string.

In the attempt with the PowerShell script you have a problem in the file path.

I don't know what the value of the sourcesFolder and I can't understand what is the + file ....

I tried to concatenate the file path in this way:

$filePath = $(Build.SourcesDirectory)\test.html
# Verify the path is correct:
Write-Host $filePath
# Output: D:\a\1\s\test.html

And I upload the file to the Summary page in this way:

Write-Host "##vso[task.uplaodsummary]$filePath"

The upload succeeded and the test.html exist in the build summary page.

So in your case you must to check the file path and fix it, after it the upload will work (you can try also put hard coded path and check if it works).

P.S - The task.uploadsuammry is a short hand to task.addattachment type=Distributedtask.Core.Summary.



来源:https://stackoverflow.com/questions/55873998/tfs-build-write-message-to-summary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!