TeamCity export CoverageReport.xml to a predefined directory - teamcity

I am trying out TeamCity for our CI.
We have a build step running NUnit for unit test and dotCover for code coverage. The process went through fine, but im just wondering if it is possible to export the Build Log and the dotCover's CoverageReport.xml to a predefined directory on the local machine.
or maybe even export all the artifacts and reports used in the build to a local folder.

Just add a build step ( command line ) that will copy over the reports that you need to the desired location locally.

Related

Build pipeline for xaml files

I am trying to have a CI/CD pipeline for my project for which the output of the development is multiple xaml files.
I am trying to build a pipeline in Azure Devops tool. For build pipelines we have to select a task (for eg: for powershell scripts there is a powershell task) . Since our project files are xamls , what could we select here and complete our build pipeline?
Basically what are the build activities(like sonarQube and HPFortify for java project) that we can do on xaml files ? If there is none, can I bypass and have an empty build so that we can enter the release pipeline without much build checks.
We dont need to package it into a separate package. It can remain as xaml files after the build and the CD pipelines can deploy it to a folder in the server.
If your build artifact is just a bunch of XAML files then simply use a copy task to copy these to $(Build. ArtifactStagingDirectory) and then use a publish drop task to take the contents of $(Build. ArtifactStagingDirectory) and store it on the server and you're done.
You don't have to have a build task you just need the files required for your release which the above couple of steps will do nicely.

Showing 0% Coverage in SonarQube (integration with Teamcity for .Net Project)

I have configured the Build steps as below
Created another Build Configuration (e.g. named "Send to SonarQube") and added the dependency on initial configuration
An artifact dependency for ".teamcity/.NETCoverage/dotCover.dcvr" file and getting artifacts from "Build from the same chain".
In the new configuration ("Send to SonarQube") added a Command Line step with the following script:
%teamcity.dotCover.home%\dotCover.exe report /ReportType=HTML /Source="dotCover.dcvr" /Output="dotCover.html"
Added SonarQube Runner to the new configuration and added additional command line argument with "-Dsonar.cs.dotcover.reportsPaths=dotCover.html"
Please suggest
Note: When i have checked the dotCover.html the coverage is showing perfectly. But the sonarqube is showing as 0% covered
Since you are using build chains, you are probably switching directories and SonarQube uses absolute paths. To confirm this, look at the html/[nnn].html files in your working directory. In html -> head -> title, does the absolute path match the source code in your current working directory when you run the report command?
So to summarize, in your "Send to SonarQube", you need to ensure:
You have your source code in the working directory
Your individual [nnn].html files have titles with absolute paths matching the source code in your working directory.
There are a few ways to ensure #2:
Way #1
Tell TeamCity to run all snapshot dependencies on the same agent.
Make sure your VCS setup is exactly the same. (For myself, I had excluded some folders in my "Send To SonarQube" equivalent, and that caused a different working directory)
Way #2
Override the Checkout Directory in your VCS setup for everything in the build chain to point to the same absolute directory.
(I haven't tried this, but it should work across agents since the agent name isn't in the directory path)

MsTest unable to copy test data files to build server

I am trying to implement automated unit testing with each build using TFS.
Problem statement :
I have created few xml files which stores test data and set to copy always. When run locally files are picked up from bin folder. When I schedule a build, build process looks for files in out folder under TestResults on Build Server. Out folder contains ddls but not the xml files. Hence unable to find files and results into build failure partially.
You can specify additional files to deploy in your test settings file:
More details here - https://msdn.microsoft.com/en-us/library/ms182475.aspx
You could also use the DeploymentItem Attribute.
https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx

copying to teamcity's out directory before running unit tests

So my situation is that I finally finished configuring TeamCity for CI. I got it to run my unit tests with some friendly help on SO.
However, many unit tests fail because there needs to be a config file alongside the unittests.dll once it's built and ready to run.
I've written a simple Command Line step with:
copy %system.teamcity.build.checkoutDir%\xx.configfile <destination>
The destination is the problem, I need it to be the Out directory teamcity creates.
TC creates SYSTEM_<machinename> <datetime>\OUT. An example:
C:\TeamCity\buildAgent\temp\buildTmp\SYSTEM_GIDEON 2015-07-02 16_51_09\Out
In there is my unittests.dll and I want to copy my config file there. What environment var or (anything else) can I use in the command line script?
The (1) Build Tests is a Step then I want to run the (2) Copy Config Step Then (3) Run Tests. After step (1) I have that xxx\xxx\Out directory and I need that directory from some variable.
I'm using Teamcity 9.0.2
Your problem is not to do with TeamCity I don't think, it's to do with the way that MSTest works. You need your .config file to be a DeploymentItem and have your tests deploy it to the directory that MSTest will run the tests in.
To be honest I'm surprised that you don't have this problem running locally, and it makes me think that you must be using some other test runner (like ReSharper) to run the tests if you have not seen this problem on your local machines.

Automatically generate Code Coverage during nightly build

I have some problems getting the code coverage .coverage file generated in nightly build.
What I have: I've configured my build to use a .runsettings file and Type of run settings : CodeCoverageEnabled
The build is correctly running all the required unit tests and measuring the code coverage, using only a selected number of assemblies (specified in the .runsettings file).
In the build report, within VS2013, I can manually export the code coverage file (a .coverage file).
What I need:
I would need to configure the build to automatically generate that .coverage file in a target folder.
How do I do that?
The .coverage file is present as a part of the test results. You can use the .runsettings to set a outputpath for the test results
<ResultsDirectory>c:\\TestResults</ResultsDirectory>
The .coverage file will be present in a subfolder within the results directory.
If you want to push it to another location you can do that via a post-build script in your nightly's build process template.

Resources