Sonarqube combined Jenkins & FAQ
The ultimate goal we introduce sonarqube component to the entire Ci environmental services, if not integrated in the current Jenkins CI, so we do a lot of work on sonarqube will be in vain. However, this is almost do not worry, because we from previous lecture can see our building operations are carried out via the command line to enter, from this point of view should be seamlessly integrated into jenkins environment, but we found the command moved intact Jenkins, things are not like so easy to imagine, but there are a variety of pit existence.
We run the following code in the previous section run over, and see what problems occur:
MSBuild.SonarQube.Runner.exe begin /k:"mytest" /n:"mytest" /v:"v8.0" /d:sonar.cs.opencover.reportsPaths="%CD%\testcover.xml"
msbuild.exe
"E:\personalproject\newTest2018\ConsoleApp1\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -output:"%CD%\testcover.xml" -register:user -target:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" -targetargs:"%CD%\bin\Debug\NunitTest.dll"
MSBuild.SonarQube.Runner.exe end
The above command will be run according to the following problems might:
Question 1 command not found
There may be children's shoes experience MSBuild.SonarQube.Runner.exe
is not recognized as an internal or external command, operable program or batch file.
Of course, some children's shoes may not encounter this problem, depending on the path environment variable settings
This interface can see there are two places to set the path, the user level is above, below is a system level, if you are in the path above the level set by the user, it can not be read to Jenkins (this refers only to the default ..) the current user variables, because Jenkins perform user and the current user is not (you can perform the whoami look at jenkins jenkins in the implementation of the user in the same user) there are two solutions: the first approach is to specify executable file MSBuild.SonarQube.Runner.exe
full path (other executable files as well), a second, adding to global configuration variables in the environment. Lane added to the global variable is convenient, but the total length of the global variable is limited, if configured too easily exceed the limit, there is a little problem like mono automatic add a lot of environment variables during the installation, if the user installed a mono, use the global msbuild sometimes cause the compiler to compile the results compiled the results and specify the full path inconsistent, which make the user's own discretion.
Problems 2 relative path
The above code we use %CD%
,,% CD% is the current directory example in front of us are implemented under the project directory, and in the environment Jenkins, the current directory is Jenkins\workspace\项目名
, if not handled properly, it will cause a compiler error.
The second paragraph msbuild.exe
is the same problem, it must be in the project directory when the project did not need to specify the name to be compiled, or if there is no sln csproj files in the current directory, you need to explicitly specify the full path for project files such asmsbuild.exe "E:\personalproject\newTest2018\ConsoleApp1\NunitTest\NunitTest.csproj"
Question 3 if the path requires quotes
This is actually a common problem, sometimes we will find the path without the quotation marks problem does not occur, sometimes problems occur, it is the author's experience, if there are no spaces in the path without quotes, if you need to be quoted. Therefore, in order to avoid unnecessary trouble, it recommended best practice is the path put in inverted commas.
Question 4 Jenkins default account can not be compiled Sonarqube project
We put all the problems are solved after completion, will find Jenkins still build fails with a message below Running the Scanner for MSBuild under Local System or Network Service account is not supported. Please, use a local or domain user account instead.
the above error clearly, Sonarqube MSbuild scanner does not support the Local System account or Network Service account, you need to use an ordinary account login. Let's talk about how deal with this problem.
We open the windows cmd whoami look at the implementation of the current user:
Right-click the 我的电脑
selection 管理
and then find inside from the management interface 服务
or input interface cmd services.msc
to open the Services management interface, locate the service management interface from the jenkins
service, right-click on 属性
the pop-up dialog box, switch to the 登陆
label, if there is no landing is a local failure, we choose此账户
Then enter the account password and click OK.
After you are done restart jenkins service and then execute the script, it can compile passed.