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.