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

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)

Related

How to configure a sonar-project.properties file for code coverage?

Current my scanner is running through and only scanning the parent and skipping the rest of my nested files. If I run sonarlint (using the cli and specifying some test and source files) , it tries to analyze 37k files instead of the few I need. I have been able to skip ~3k files by adding the <sonar.skip>true</sonar.skip> property to a pom file. However, I still can't configure the project to run across certain sub-folders and print out some kind of code coverage test. (Is JaCoCo needed for the latest version(6.3,0)? Or can code-coverage be handled through some configuration?).
If Sonar seems to be analyzing too many files, it is probably because you had not set the sonar.sources=src/main/java in your sonar-project.properties file, so it defaults to the basedir and includes everything.
SonarQube can't do code-coverage itself, it just reports on coverage-reports from a tool like JaCoCo. It is funny they don't clarify these things in https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner --but with enough digging, you can find good info on that site.

How to access test artifacts from Jenkins if test fails

I have a Maven project which performs a number of time consuming tests as part of the integration-test Maven cycle. I'm using Jenkins as the CI server.
During the integration test a number of files are produced in the target folder. For example, an "actual" BMP file is produced and compared to an "expected" BMP file. If the test fails, I need to look at the files in the target folder to determine how to deal with the error. Maybe the actual BMP looks fine and so it should be promoted to the new expected BMP. On the other hand, it may reveal a problem that requires a code fix.
The thing is I don't have any way to get access to these files, other than to ssh into the CI server and manually scp the files over to my own machine for closer inspection. It would be extremely helpful if I could access these files from the Jenkins web interface.
I tried using the build-helper-maven-plugin to attach the relevant files as Maven artifacts, but the problem is that there is no suitable phase in Maven that executes after an integration-test, if any test fails.
What can I do? Can I use the "Copy Artifact" plugin for this?
1) The files in the target folder can be accessed using a link such as /ws/projectname/target/filename...
2) Rather than typing the url each time, the SideBar plugin can be used to add a link to the file to Jenkins' left menu, making it easily accessible.
You need to copy your files into your workspace in a build step and archive them from there - Jenkins lets you specify artifacts only relative to the workspace.
I usually create a directory keyed by the BUILD_ID in the workspace, so that artifacts from different builds do not get mixed up in case I do not clean the workspace and archive from there (specifying ${BUILD_ID}/**/* in the archiving step).
In case your build fails before it can run the copying step and because of it does not do the copy, take a look at this question.

ld: library not found for -lLIBRARY_NAME, only when trying to build using jenkins

I have a project that when built from my machine everything runs smoothly. However, when I push my changes and try to generate the build using jenkins, I'm getting the library not found error message.
This is weird because if I login into the jenkins server and I try to do a manual build, everything works as expected, perfect. It's only when I build from withing jenkins that my build is failing.
I'm assuming LIBRARY_NAME as the name of whatever library, in my case is an internal static library.
Any suggestions?
EDIT:
I've setup: Library Search Headers, Other Linker Flags, Target Dependencies, Proper Architectures
I wrestled with this for three weeks until I accidentally stumbled onto this with the help of a coworker. Basically, you must be sure that the path structure created in your repository is replicated in the .jenkins workspace. To do this just be sure that in your project/job configuration in jenkins the Source Code Management > Subversion > Repository URL field must be at the same level as specified in jenkins in your script or Build > Execute Shell > Command field. So here are my settings as an example:
above Jenkins URL = https://myDuncwa.local/duncwa-repo
above Jenkins Build = "cd $WORKSPACE/mobileapps/projects/PictureBoard/trunk/PictureBoard" and line 2 "xcodebuild -project PictureBoard.xcodeproj" no quotes.
above Subversion URL repository = https://myDuncwa.local/duncwa-repo
This will cause the directory structure mobileapps/projects/PictureBoard in my repository to replicated in the .jenkins/jobs/PictureBoard/workspace/mobileapps/projects/PictureBoard directory that is created automatically by jenkins. Note: 1) This will copy the entire repository so be prepared to change this later and 2) .jenkins is a hidden directory created by the install in the installing user's home directory or "~/"

Advice needed with Teamcity artifact paths

For a .NET Developer, the Teamcity artifact paths are not very straightforward.
Per project I do, I have a folder called BuildTools and, within it, folders called Drops and Inputs (drops being the reports and outputs inputs being the config files for various command line apps).
BuildTools/Drops/NDependOut => GenericSolution/Drops/NDepend
Is this correct? BuildTools is from the root of the (custom) checkout dir, and then GenericSolution is from the root of the artifacts path (Called "Artifacts" folder).
The other problem I have is that the NDepend report has a lot of images etc in the same folder as the .html file. How would I upload this? Do I upload the entire folder (in which case, is the syntax above correct?)
In general this is right. TeamCity has an option to zip artifacts before publish. For that use the following syntax
Folder/folder/*/ => destfolder/archive.zip
Another trick is to use TeamCity service message to publish artifacts dynamically from build script.

Change build label for Project Cruisecontrol.net

After some unexpected changes on the Cruisecontrol.net buildserver the artifacts directories were gone, and the build labels were reset on all projects. How can I change the build label value on the projects? We are using CCNetLabel variable in our scripts.
I tried updating the .state file with no success. it just overwrites the values on the next build. Also tried manipulating the latest log file in the artifact directory
You can use the <initialBuildLabel> value to set it in your .config file. This documentation for the Default Labeler gives more detail, but here is their example:
<labeller type="defaultlabeller">
<initialBuildLabel>1</initialBuildLabel>
<prefix>Foo-1-</prefix>
<incrementOnFailure>true</incrementOnFailure>
<labelFormat>00000</labelFormat>
</labeller>
I think this is what I did in my build config when I needed to do this, but have since removed it once it got going at the number I wanted.

Resources