1
votes

This is my first blog or query. I am very new to TFS Admin role and sonarqube tool.

We are using TFS 2013 as an ALM in our project, the project is based on .Net Application (new to .NET as well).

As per the client requirement, I am trying to integrate the "SonarQube 5.2" with the customized build process template instead of default template.

I installed the "SonarQube 5.2" on "ABC server" and my "TFS server/build agent" is on "XYZ". I installed the SonarQube Scanner for MSBuild 2.1 on XYZ server and updated the environment variables & sonarqube runner xml accordingly.

As per the standard link I am not using default template:-http://docs.sonarqube.org/display/SCAN/From+Team+Foundation+Server+2013 and using a customized build template, which hadn't have pre/post build argument options.

So I edited in the customized build process template, added hooks for pre/post build scripts activities and updated the properties similar to the mentioned link :- http://www.colinsalmcorner.com/post/build-script-hooks-for-tfs-2012-builds

Note: As per the above link, I didn’t update "Challenge 2 – Environment Variables" part in the process template as I am not running any powershell script only wanted to execute the MSBuild.SonarQube.Runner.exe.

Used following activity & properties within the customized process template (refer above link):

*ConvertWorkspaceItem activity, set the following properties:

• DisplayName: “Get pre-build script local path”
• Input: PreBuildScriptPath
• Result: preBuildScriptLocalPath
• Workspace: Workspace

Set the following properties in the InvokeProcess activity:

• Arguments: String.Format(" ""& '{0}' {1}"" ", prebuildScriptLocalPath, PreBuildScriptArgs)
• DisplayName: “Run pre-build script”
• FileName: “PowerShell”
• Working Directory: SourcesDirectory*

Note: Same thing done for post build script

Sequentially, I placed these pre and post script activities under "Try, Compile and Test" activity of the process template.

In the MS build definition which is using the customized process template, I am setting below values in build process parameters (location/path of runner.exe on XYZ server) :

Pre-build script path : C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe

Pre-build script arguments : begin /n: /v:< project version #> /k:

Post-build script path : C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe

Post-build script arguments : end

But after all these changes, my build is getting partially successful and sonarqube integration is failed with the following error:

*The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.

Possible causes:

  1. The project has not been built - the project must be built in between the begin and end steps

  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported

  3. The begin, build or end steps have not all been launched from the same folder*

Note: On XYZ server (TFS build server) we do have MSBuild 12.0 and build is happening under SourcesDirectory as ".sonarqube" folder is getting created within the same directory.

Also on XYZ server's command prompt (within the location of SourceDirectory or where the ApplicationName.sln is available), I ran following sonarqube commands, my analysis was successful and reports generated on Sonarqube dashboard:

- MSBuild.SonarQube.Runner begin /n:<project name>  /v:< project version #>  /k: <project key>
- "C:\Program Files (x86)\MSBuild\12.0\Bin\Msbuild.exe" "ApplicationName.sln" /p:Configuration=Debug /p:Platform="Any CPU"
- MSBuild.SonarQube.Runner end

Kindly go through this, it will be a great help if someone can guide me and provide some concrete explanation to resolve this.

Let me know if you need any other information.

2
Did you try with the default build template? How's the result?Cece Dong - MSFT
I tried default template with pqr.sln file, got so many dlls and other artefacts accessing and copying issues. Even developer was not able to rectify it. However we used same pqr.sln in another build definition with customised build template (not included sonarqube arguments & path) was built successfully.abhishek verma
Can you check if the MSBuild.SonarQube.Runner and MSBuild is running from the same working directory?Eddie Chen - MSFT
MSBuild.SonarQube.Runner is installed on "C:\sonarquberunner\" and MSBuild is under "C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe" and my build directory on TFS server is "D:\data\Build\$(BuildAgentId)\$(BuildDefinitionPath)" (location of source code for build). Now within properties of the build definition and build process template I have mentioned the SourceDirectory as working directory, hence the .sonarqube is getting created at builddirectory/sourcedirectory. At ".sonarqube/out" folder the sonar-project.properties is not getting created (getting possible causes issue).abhishek verma

2 Answers

2
votes

as I read in your comment:

MSBuild.SonarQube.Runner is installed on "C:\sonarquberunner\" and MSBuild is under "C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe" and my build directory on TFS server is "D:\data\Build\$(BuildAgentId)\$(BuildDefinitionPath)" (location of source code for build).

You have installed MSBUILD 12, but the Build agent is calling the version 4.0

You need to modify your build process template in order to achieve that.

Find the Run MSBuild activity in your build template and set the ToolPath = “C:\Program Files (x86)\MSBuild\12.0\bin\” or the path of your MSBUILD 12

0
votes

You may try to specify the /n:/k:arguments:

/k:"the project key of the SonarQube project to which the build definition relates"

/n:"the project name of the SonarQube project"

Also, instead of Post-build script path and Post-build script arguments, try to set the Post-test script path to the full path to MSBuild.SonarQube.Runner.exe, and set the Post-test script arguments to end.

Check the screenshot below:

enter image description here