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.
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
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:
Related
I've succeeded build with TFS 2015 Using MSbuild task. Now I've added Sonar qube tasks (SonarQube for MSBuild - Begin Analysis & End Analysis), find the Sonarqube settings below:
1. What is the Project key & how do we get it? I just gave Project Name as key.
Immediately on build trigger threw error/warning:
There are issues with the request or definition that may prevent the
build from running:No agent could be found with the following
capabilities: msbuild, java, msbuild, java. Queue the build anyway?
On Trigger Build further, Build failed with following error
No agent found in pool which satisfies the specified demands:
msbuild
java
msbuild
msbuild java Agent.Version -gtVersion 1.94.0
On cross-checking, i see that under General section in Build definition : Demand for MSBuild & java exists.
2. Am i correct or missing anything/settings?
I've configured Service Endpoint for SonarQube also. Find the screen shot below:
Please suggest on my error & queries highlighted.
When adding new task which required agent capabilities you need to add it to the agent.
The capabilities must be installed on the build servers where the agents are located.
UPDATE:
I just installed sonar qube on my test environment.
I got the same exception as you did, fixed it by installing java and msbuild .
Check,if those capabilities exists under your agent :
I'm trying to launch Sonarqube on a .NET Core 2.0 solution from Jenkins using SOnarQube MsBuild on Windows.
It works fine when i execute the following script from Jenkins workspace:
C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe begin /k:XXXX.Campaigns /n:CI /v: /d:sonar.host.url=http://x.x.x.x:9000 /d:sonar.verbose=true /d:sonar.projectBaseDir="C:\Program Files (x86)\Jenkins\workspace\CI"
dotnet clean
dotnet build
C:\SonarQube\bin\MSBuild.SonarQube.Runner.exe end
But when i execute the same command from Jenkins, i got this message:
The SonarQube MSBuild integration failed: SonarQube was
unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in
between the begin and end steps.
An unsupported version of MSBuild
has been used to build the project. Currently MSBuild 14.0 upwards
The begin, build or end steps have not all been
launched from the same folder
I use Jenkins 2.46.2 - MSBuild 15 - Sonarqube 6.7 & Sonar MsBuild 4.0.2.892. I tried using Jenkins build steps, command step, command step with a script without success. On a classical .Net 4.5.2 project, it works.
Jenkins was running as local system user. I change it to a normal Windows user and it did the trick. dotnet build was not using Sonarqube dedicated targets.
Thanks you #Valeri!
Currently having the following errors on the "Complete the SonarQube analysis" step of our TFS 2017 build:
2017-12-05T22:04:24.5437340Z ##[error]System.Management.Automation.CommandNotFoundException: The term 'Get-TaskVariable' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2017-12-05T22:04:24.5837397Z ##[error]System.Management.Automation.RuntimeException: The MSBuild.SonarQube.Runner executable could not be found. Check that the build definition includes a SonarQube Pre-Build step ---> System.Management.Automation.RuntimeException: The MSBuild.SonarQube.Runner executable could not be found. Check that the build definition includes a SonarQube Pre-Build step
SonarQube version: Version 6.7 (build 33306)
SonarQube Scanner for MSBuild version: 3.0.2
The "Prepare the SonarQube Analysis" step completes prior to the Visual Studio build step with no errors.
According to the error seems SonarQube.Runner didn't captured by TFS build agent.
Double confirm the configuration in SonarQube Scanner for MSBuild - Begin Analysis task which used to prepare the analysis before executing the build. Such as SonarQube Endpoint.
Besides, on the build agent:
Make sure the .NET Framework v4.5.2+ is installed
Make sure the Java Runtime Environment 8 is installed
Source Link: Analyzing with SonarQube Extension for VSTS/TFS
Try to create a new build definition with a simple test project to see if got the same error.
My jenkins project does 2 checkouts, one from a framework and one from an application A that uses the framework.
I want to run a sonar scanner on application A.
I Have 6 building steps in jenkins
Execute Windows batch command : nuget.exe restore "%WORKSPACE%\Framework\branches\1.0.1.0\Framework.sln"
Execute Windows batch command : nuget.exe restore "%WORKSPACE%\AppUsingFramework\branches\v1.1.3\AppUsingFramework.sln"
Build a Visual Studio project or solution using MSBuild : build framework
SonarQube Scanner for MSBuild - Begin Analysis // HOW DO I SET THE FOLDER TO %WORKSPACE%\AppUsingFramework\branches\v1.1.3 ?
Build a Visual Studio project or solution using MSBuild : build the application
MSBuild Build File : AppUsingFramework\branches\v1.1.3\AppUsingFramework.sln
SonarQube Scanner for MSBuild - End Analysis
I get this message :
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
The begin, build or end steps have not all been launched from the same folder
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
So I suspect that I should specify working folder (%WORKSPACE%\AppUsingFramework\branches\v1.1.3) to sonar when I start it, how do I do that ?
I use :
Jenkins 2.60.2
SonarQube Scanner for MSBuild 3.0.1.635 (install automatically from github)
MSBuild 15
By removing the unnecessary build framework step (it's built in the app already) and by only specifiying AppUsingFramework.sln without path the sonar scan succeed.
I'm trying to do a teambuild for a VS2015 solution with TFS2013.
On the buildserver VS2015 is installed and I changed the buildtemplate so msbuild has an argument \tv:14.0, but when a start a build I get the following error:
C:\Program Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets (96):
Invalid static method invocation syntax:
"[Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName($(TargetPlatformIdentifier),
$(TargetPlatformVersion))". Method
'Microsoft.Build.Utilities.ToolLocationHelper.GetPlatformSDKDisplayName'
not found. Static method invocation should be of the form:
$([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a,
b)).
The buildserver has been restarted but I still get the error.
I also checked this thread: Build failed in TFS but no real answer was given there. Is there anyone that knows how to solve this.
I was experiencing the exact same error. I determined that TFS2013 was the RTM version so we installed TFS2013 Update 5. Now if I run using the *.12.xaml process template with the /tv:14.0 /p:VisualStudioVersion=14.0 parameters the build succeeds. I have also made a copy of the *.12.xaml build process and named it *.14.xaml and changed the Run MSBuild steps ToolVersion property to "14.0" and this build works as well, without the parameters.
You need to customize the build process template by finding all the Run MSBuild for Project MSBuild activity, then set the ToolVersion to "14.0" and set ToolPath to target to MSBuild14 (by default: "C:\Program Files (x86)\MSBuild\14.0\Bin"). After that, check in the build process template and re-queue the build.
Check the solutions here:TFS 2013 building .NET 4.6 / C# 6.0