TFS build write message to summary - tfs

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

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.

Related

TFS Combine Variables with String

We are conducting a database release in TFS SQL 2015. The plan is to concatenate and variables with strings. Error Message below,
For our deployment release, we have sqlpackage :
C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe
Method 1 :
/Action:Publish /SourceFile:"$(build.artifactstagingdirectory)"\Datawarehouse.dacpac
/Profile:"$(build.artifactstagingdirectory)"\Dev.Publish.xml
Method 2 (switching quotes to end):
/Action:Publish /SourceFile:"$(build.artifactstagingdirectory)\Datawarehouse.dacpac"
/Profile:"$(build.artifactstagingdirectory)\Dev.Publish.xml"
For some reason, TFS is not populating the variable in the logs. How do we conduct this? We want to concatenate a variable with a fixed string.
Error Message:
2018-12-13T18:43:49.0945356Z *** Error parsing connection string: Could not find a part of the path 'D:\testabcd....\$(build.artifactstagingdirectory)\Dev.Publish.xml'..
You may create simple cmd file like this:
echo off
echo 1: %1
echo 2: %2
echo 3: %3
Then copy it to work folder and add build step:
Result on my environment for the Method 1:
Method 2:

AZCopy Get list of failed transfer files

When running azcopy it shows that "Transfer failed: 5" the output $Result does not tell which files failed.
$Result = & $azcopyLocation /Source:$TempDestination /Dest:$deploymentPath /destkey:$destinationKey /NC:30 /S /Y
Is there a way to find out which files failed to copy?
Add "/V:" and enter a directory and txt file name, like:
/V:C:\AzCopy\Logs\Log.txt
It creates a log file which says which fails were uploaded and which were not and any errors that might occur.

How to use file parameter in jenkins

I am executing parameterised build in jenkins to count no. of lines in file which has 1 file parameter. Its file location is pqr. The name of the script file is linecount.sh which is saved at remote server. When i tried to execute it using command sh linecount.sh filename, it works perfectly from jenkins. But as i remove filename from the argument and execute same script as parameterised build it is showing below error on console :
Started by user Prasoon Gupta
[EnvInject] - Loading node environment variables.
Building in workspace users/Prasoon/sample_programs
Copying file to pqr
[sample_programs] $ /bin/sh -xe /tmp/hudson3529902665956638862.sh
+ sh linecount.sh
PRASOON4
linecount.sh: line 15: parameterBuild.txt: No such file or directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I am uploading file (parameterBuild.txt) from my local machine. Why is it giving this error?
My doubt is in shell script I used argument as $1. How can I refer this when I am taking file as parameter.
The uploaded file will not retain the same name as it has on your local computer. It will be named after the File location argument specified in the file parameter settings:
In this example I will get a file called file.txt in my workspace root, regardless of what I call it on my computer.
So if I now build my job and enter the following in the parameter dialog (note that my local filename is table.html):
Then I get the following in the log (I have a build step which does ls -l):
Building on master in workspace /var/lib/jenkins/workspace/fs
Copying file to file.txt
[fs] $ /bin/sh -xe /tmp/hudson845437350739055843.sh
+ ls -l
total 4
-rw-r--r-- 1 jenkins jenkins 292 Feb 15 07:23 file.txt
Finished: SUCCESS
Note that table.html now is called file.txt, e.g. what I entered as File location.
So in you're case the command should be:
sh linecount.sh pqr
There is a a bug since ages that makes impossible to use fileParameter:
Handle file parameters
file parameter not working in pipeline job
There is a workaround for this issue https://github.com/janvrany/jenkinsci-unstashParam-library
and in a pipeline script you do:
library "jenkinsci-unstashParam-library"
node {
def file_in_workspace = unstashParam "file"
sh "cat ${file_in_workspace}"
}
If it's to do with Free-Style job & if your configuration looks similar to this - https://i.stack.imgur.com/vH7mQ.png then you can run simply do sh linecount.sh ${pqr} to get what you are looking for?

Getting error for Data stage compare command line tool

I am using a utility provided in Data Stage 9.1 diffapicmdline.exe to compare two jobs from different environment. I am using following batch script code to read the job names from text file in loop:
#echo off
SET var=
for /f "delims=" %%i in (grm_deploy.txt) do (C:\IBM\InformationServer91\Clients\Classic\diffapicmdline.exe /lhscd "/d=cs1cd:9080 /h=cs1i04 /u=user/p=password cs1cdhbi04/IST_GRM %%i" /rhscd "/d=cs1cd:9080 /h=cs1i04 /u=test /p=Pass cs1cdhbi04/TEST_NIMISH %%i" /t job /ot html /ol E:\compare_output.html)
echo this is the end
However I am getting following error:
D:\dataStage Components\Scripts>read_file.bat
Validating syntax of /lhscd.
Unknown flag specified 'jbLoadStgARxAR'
this is the end
Can anyone let me know what is going wrong over here?

Text parsing a file path in batch script

I'd like to set a file's name to a variable in a batch file. I'm already pulling the file name by pulling the total path length. Is there a way I can parse the path to only give me back the file name?
The particular script that I use to pull the path looks like this:
for /f "delims=_" %%J IN ('forfiles /p "%%F" /m *.extension /c "cmd /c echo #path"')
DO start "Program" /D "c:\fullpath" /Wait program -r %%J
Also, if there's an easier way to pull the file name and put it into a variable I'm open to that as well.

Resources