Include Build number in Jenkins test result file - jenkins

I have a test project in Jenkins. And each time I build my project it says.
The results file "My File Path" already exists. Please specify a
different results file or verify the existing file is no longer needed
and delete it.
So I've decided to include the build number in the name of my result file.
And I'm using my result file to generate some graphical output also.
How can I include my Build Number in both locations
This is the windows batch command execution
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\mstest.exe"
/testcontainer:"%WORKSPACE%\TestAutomation\bin\debug\TestAutomation.dll"
/resultsfile:"%WORKSPACE%\results.xml"
And I'm using my result file as follows.
How can I change both these locations to add current build number in my result file as followingformat
result_BuildNumber.xml

Try this,
result_%BUILD_NUMBER%.xml - for batch
result_$BUILD_NUMBER.xml - for shell
BUILD_NUMBER is environment variable.

Related

Copy the Setup file to a folder named with version number in TFS

We are using TFS build and when I built the project in TFS build, it also creates a setup file.
For example, my application version is V1.2.3 (its from assembly.cs) the location of the setup file is C:\myproject\setup\setup.exe
Well I want to copy this setup exe into the following folder
C:\products\producta\ V1.2.3
So I just need to get version number to create a folder named "V1.2.3". For copying and creeating, i can make a batch file but i do not know how to get version number. TFS has some variables for example Build.SourceVersion
but these variables do not give me the product's version number.
How I can do this thing?
You have to write a script to do this.
1) Powershell script to read the build number from assemblyInfo.cs
$myAssemblyVersion = major.minor.patch -> Read from assembyInfo.cs
$versionWithBuildId = '{0}.{1}' -f $myAssemblyVersion, $Env:BUILD_BUILDID
2) Update the TFS internal build number from current build
Write-Verbose -verbose "##vso[build.updatebuildnumber]$versionWithBuildId"
After that you can use the "Copy Files" or "Publish Artifact" step.
With "Copy Files"
Target Folder = "C:\products\producta\$(Build.BuildNumber)"
With "Publish Artifact"
Artifact Name = "$(Build.BuildNumber)"
Path = "C:\products\producta"

What do I use for summary file when publishing code coverage results in TFS 2015?

Unfortunately imgur is blocked here at my workplace, so instead of screenshots of my build definition I will have to explain my build definition settings to the best of my ability.
I have two build steps, the first is a maven build step that runs the "package" goal. Under the code coverage section of the maven settings I have the CodeCoverage Tool set as "Cobertura", which is what we use on our local boxes when maven building.
My second build step is "Publish Code Coverage Results". I am not sure exactly what to put for my summary file in the settings of this build step. I think that the problem is that the build agent takes the cobertura folder off of the build machine and puts it somewhere else not on the build machine. This is the log entry for what it is doing:
Uploaded artifact 'C:\TFS_BUILD_AGENTS\agent-1\_work\3\s\target\site\cobertura' to container folder 'Code Coverage Report_35241' of build 35241.
So I either need the Summary File location for wherever it is uploading to, or I need to have it not upload the folder like it is currently doing.
This is what I have as the summary file right now, which does not work:
Code Coverage Report_$(Build.BuildId)\coverage.xml
You could check in this file to TFS and map it down to the build agent server. Then you could some build variables(like $(Build.SourcesDirectory) which represents 'C:\TFS_BUILD_AGENTS\agent-1_work\3\s') to get the file.
So you need to put C:\TFS_BUILD_AGENTS\agent-1\_work\3\...\***.xml. Make sure the file is located at the path your specified.
If the file you want to upload is generated after the step1, please check which path is locates and point it in the Summary file blanket.

TFS build renaming the cspkg file

I currently use TFS build for my Azure cloud service project.
as a output of that .cspkg and .cscfg file is created after the successful build.
is there any way to add the $(Build.BuildNumber) to my .cspkg file
say for eg: currently my output file looks like
SchoolWebPortalAzure.cspkg
is it possible to rename like SchoolWebPortal_1.0.0.1.cspkg in the tfs build definition.
thanks,
kind regards,
Snegha
You could use the Run Command Line task or do it in a PowerShell script in build.
1). Add the Inline Powershell task from the marketplace before the copy task in build definition.
2).Enter the following Powershell in the text area
Param (
[string]$pathToFileToRename
)
Rename-Item $pathToFileToRename Helloworld_$(Build.BuildNumber).exe
3). Enter any required arguments in the arguments text box (you could
use environment variables) e.g. -pathToFileToRename $(Build.SourcesDirectory)\somepath\CurrentName.exe
Then you will get the renamed file in the drop folder.

Custom TFS Build Log Files

I have a TFS build in a Git team project that uses the default template. It builds a .proj file containing a single target that executes a .PS1 file in Powershell.exe.
The .PS1 generates its own log file. I have been trying to figure out how to get this file to copy to the drop directory \logs folder. From what I can tell, TFS only copies specific files to this output directory:
ActivityLog.AgentScope.[id].xml
ActivityLog.xml
build.log
Anyone tried getting custom logging info to this directory? I tried writing to build.log but that failed with errors.
I like #MrHinsh's answer better than mine, but I found that you can write to a file at this location: $(TF_BUILD_DROPLOCATION)\logs during build.
I assumed that since the path doesn't exist until the log files are copied it would not work. But it does... the TFS/MSBuild log files are simply merged in. And it even seemed to work with a name conflict. For example, if your file is named build.log, MSBuild's will be renamed to build.01.log.
In your PowerShell you can easily execute Host-Write to write to the Build log. All of the standers output methods are captured, although you need to use the "-verbose" tag to get the text to always write.

using ant script to exceute a batch file

this is a batch file that i have. It is located in C:\Work\6.70_Extensions\Lab Tools\ folder.
ANT.BAT:
set CLASSPATH=%CLASSPATH%;.;c:\JavaMail\javamail-1.3\mail.jar;c:\JavaMail\javamail-1.3\mailapi.jar;c:\JavaMail\javamail-1.3\pop3.jar;c:\JavaMail\javamail-1.3\smtp.jar;c:\JavaMail\jaf-1.0.2\activation.jar
CALL "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"
#echo on
%ANT_HOME%\bin\ant -logger org.apache.tools.ant.listener.MailLogger -q -buildfile "Master Build.xml"
pause
along with ant.bat, i have a Master Build.xml file located inside the same folder.
When i double click on ant.bat, it will execute the Master Build.xml ant script properly.
However, whenever i try to use another application to open the batch file's absolute path, it always state that Master Build.xml file does not exist!
I tried to open the absolute path using both console application and another ANT Script(via Cruisecontrol framework) but both gives the same error. What is the error here?
for your information here is what ive done with cruisecontrol:
create config.xml (to set intervals for builds)
create nightbuild.xml (so that config.xml will go into it to perform required tasks)
nightbuild.xml will run several console applications to sort files, checkout files from version control etc
lastly, nightbuild.xml will execute ant.bat file to execute the build
These files, config.xml and nightbuild.xml are found in C:\build
When you execute from a directory other than the one containing Master Build.xml, Ant will fail to find the build file, which it expects to be in the current working directory.
You could set an additional environment variable to specify the path to the build file, e.g.
%ANT_HOME%\bin\ant -buildfile "%MASTER_BUILD%\Master Build.xml"
If you set your variable to an absolute path (e.g. C:\Work\6.70_Extensions\Lab Tools) then it will always work. If you use a relative path (e.g. .\Lab Tools), then it will only work if executed from the relative root dir.
(BTW, life will probably be easier if you use buildfiles without spaces in their names, e.g. master_build.xml rather than Master Build.xml).

Resources