I inherited the responsibility for a SonarQube Linux server which was running version 5.1 and analyzing dozens of Unity C# projects. After upgrading it to SQ 6.1 I discovered that support for analyzing C# projects on non-Windows systems was dropped in version 5.5, so I downgraded it to version 5.4 for the present time.
I have subsequently set up a Windows system as a Jenkins node and SonarQube server. However, the projects I am hoping to evaluate with SonarQube are (mostly) developed on and (always) built on macOS in Unity and therefore lack MSbuild solution files. Is it at all possible for me to use SonarQube within these constraints, short of adding Visual Studio-specific code to the projects? Is there some kind of dummy solution file that I could add to the projects that would allow them to be analyzed without the expectation of a working binary being produced (along the lines of parsing/tokenizing without compiling/linking)? Thanks.
Here is the procedure I have developed for analyzing Unity projects in SonarQube via Jenkins.
A user-facing Jenkins job with the following settings and options, among others specific to my environment.
PROJECTKEY
PROJECTNAME
PROJECTVERSION
refs/heads/master
.HOME=C:\Users\Jenkins
(or as appropriate for your system). This environment variable makes it possible for git to find the correct ssh credentials to use with the Git server. You'll need to put your git private key in %HOME%\.ssh
; that is documented elsewhere and left as an exercise to the reader.SonarQube_Scanner
.log.zip
.A non-user-facing Jenkins job (SonarQube_Scanner) with the following settings and options.
Build Environment—Inject environment variables to the build process checked.
Properties Content contains
`LANG=en_US.UTF-8`
Build
Execute Windows batch command contains
set FILENAME=%WORKSPACE%\client\Assets\Editor\SQMenuItems.cs
REM Yes, this syntax works and is sooo much more readable
> %FILENAME% ECHO using UnityEditor;
>> %FILENAME% ECHO public static class SQMenuItems {
>> %FILENAME% ECHO static void AssetsOpenCSharpProject() {
>> %FILENAME% ECHO #if UNITY_5
>> %FILENAME% ECHO EditorApplication.ExecuteMenuItem("Assets/Open C# Project");
>> %FILENAME% ECHO #else
>> %FILENAME% ECHO EditorApplication.ExecuteMenuItem("Assets/Sync MonoDevelop Project");
>> %FILENAME% ECHO #endif
>> %FILENAME% ECHO EditorApplication.Exit(0);
>> %FILENAME% ECHO }
>> %FILENAME% ECHO }
"C:\Program Files\Unity_5.5.2\Editor\Unity.exe" -quit -batchmode -nographics -logFile "%WORKSPACE%\log.txt" -buildTarget android -projectPath %WORKSPACE%\client -executeMethod SQMenuItems.AssetsOpenCSharpProject
"C:\Program Files\7-zip\7z.exe" -tzip a log.zip log.txt
.sln
and .*proj
files that MSBuild needs. The .sln
and .*proj
files are typically in the .gitignore
file and therefore not in the repository.SonarQube Scanner for MSBuild - Begin Analysis
${PROJECTKEY}
.${PROJECTNAME}
.${PROJECTVERSION}
.Additional arguments
/d:sonar.exclusions=**\\SQMenuItems.cs
Execute Windows batch command
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /maxcpucount /nr:false /nologo /target:rebuild /verbosity:quiet client\client.sln
client\client.sln
above to match your environment. I haven't yet tried replacing that with an environment variable defined in the user-facing Jenkins job.SonarQube.Analysis.xml
file specifically prohibits assigning the properties sonar.projectName
, sonar.projectKey
, and sonar.projectVersion
.