JetBrains / TeamCity.SonarQubePlugin

A plugin for TeamCity server allowing you to configure and run SonarQube analysis from the CI
Apache License 2.0
53 stars 31 forks source link

Need explanation for "Base dir" with MSBuild Runner. #59

Open Lexus-3141 opened 5 years ago

Lexus-3141 commented 5 years ago

Hi. Some plugins for SonarCube works with previously prepared reports. 'SonarQube Runner' step doesn't define any base directory in its output. And we can put reports to root of working dir and set this value in plugin configuration. Unlike this 'msbuild runner' steps define base dir accodingly to VSC checkout rules and we got dependence on checkout rules for plugin configs. [09:45:12][Step 6/9] INFO: Base dir: C:\TeamCity\buildAgent\work\c740ee6f41af4f14\MonitoringService2 If it has only one repo it's not a problem, we can set config like '..\dependency-check-report.html'. But what a behavior do we can expect if we have few git repos in build? How is base dir defining?

Linfar commented 5 years ago

When you have several VCS roots in one configuration then they all are checked out to one directory according to checkout rules.

Then by default all steps are executed in this shared checkout directory. Most of the runners have Working directory field hidden under advanced options.

If you need to access the directory from the script it's better to avoid using relative paths (..\report.html) - it's better to use build parameters instead. There's teamcity.build.checkoutDir parameter holding absolute path to the checkout directory. So you can use %teamcity.build.checkoutDir%\report.html instead of relative path - this will be much more reliable.

But for report files I can recommend you using another directory - there's a temporary directory accessible by parameter system.teamcity.build.tempDir. This directory will be cleaned after the build.

In the same way you can pass this report to other runners (eg to the SonarQube Runner). Your first step can generate a report in some well-known location (%system.teamcity.build.tempDir%\tests.html) and then the same path can be used in SonarQube.

Lexus-3141 commented 5 years ago

I've tried to using teamcity parameters already. But it's unsuccessful because it's not work with dependency-check plugin or may be with any sonarqube plugin at general. [10:31:34][Step 7/7] 10:31:34.775 INFO - Dependency-Check HTML report does not exists. Please check property sonar.dependencyCheck.htmlReportPath:C:\TeamCity\buildAgent\work\a768aae0f58b116\%ProjectRepo%\%ProjectFolderPath%\dependency-check-report\dependency-check-report.html

I will use '..\' for now.

Linfar commented 5 years ago

Could you describe how did you specify this path? In TeamCity UI or in some scripts?

Lexus-3141 commented 5 years ago

It was in SonarQube web UI only like this. image

Lexus-3141 commented 5 years ago

Update.. Report files was placed by script.

Lexus-3141 commented 5 years ago

Upd: Base dir defining logic is unpredictable for me. I've tried to build one more project (IIS wcf service). One repository, one checkout rule (+:=>repo)

At first I'd created build pipeline and got this: Sadly for me Base dir for dependency-check plugin was C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISService

[19:24:37][Step 12/12] INFO: Project key: Admins_TestDeployIIS [19:24:37][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISService [19:24:37][Step 12/12] INFO: Working dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\.sonarqube\out\.sonar [19:24:37][Step 12/12] INFO: Load project settings for component key: 'Admins_TestDeployIIS' [19:24:37][Step 12/12] INFO: Load project settings for component key: 'Admins_TestDeployIIS' (done) | time=14ms [19:24:37][Step 12/12] INFO: Load project repositories [19:24:37][Step 12/12] INFO: Load project repositories (done) | time=56ms [19:24:37][Step 12/12] INFO: Load quality profiles [19:24:37][Step 12/12] INFO: Load quality profiles (done) | time=43ms [19:24:37][Step 12/12] INFO: Load active rules [19:24:38][Step 12/12] INFO: Load active rules (done) | time=457ms [19:24:38][Step 12/12] INFO: Indexing files... [19:24:38][Step 12/12] INFO: Project configuration: [19:24:38][Step 12/12] INFO: Indexing files of module 'TestIISService.csproj' [19:24:38][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISService [19:24:38][Step 12/12] INFO: Source paths: ForTests.cs, Service.svc.cs, IService.cs, Properties/Assembly... [19:24:38][Step 12/12] INFO: Indexing files of module 'TestDeployIIS' [19:24:38][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISService [19:24:38][Step 12/12] INFO: 10 files indexed

Then I added unit tests steps, and suddenly Base dir was changed! C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo

[19:33:07][Step 12/12] INFO: Project key: Admins_TestDeployIIS [19:33:07][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo [19:33:07][Step 12/12] INFO: Working dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\.sonarqube\out\.sonar [19:33:07][Step 12/12] INFO: Load project settings for component key: 'Admins_TestDeployIIS' [19:33:07][Step 12/12] INFO: Load project settings for component key: 'Admins_TestDeployIIS' (done) | time=16ms [19:33:07][Step 12/12] INFO: Load project repositories [19:33:07][Step 12/12] INFO: Load project repositories (done) | time=56ms [19:33:07][Step 12/12] INFO: Load quality profiles [19:33:07][Step 12/12] INFO: Load quality profiles (done) | time=33ms [19:33:07][Step 12/12] INFO: Load active rules [19:33:07][Step 12/12] INFO: Load active rules (done) | time=453ms [19:33:07][Step 12/12] INFO: Indexing files... [19:33:07][Step 12/12] INFO: Project configuration: [19:33:08][Step 12/12] INFO: Indexing files of module 'TestIISServiceTests.csproj' [19:33:08][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISServiceTests [19:33:08][Step 12/12] INFO: Test paths: TestIISServiceTests.cs, Properties/AssemblyInfo.cs, packages.co... [19:33:08][Step 12/12] INFO: Indexing files of module 'TestIISServiceTestsInt.csproj' [19:33:08][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo\TestIISServiceTestsInt [19:33:08][Step 12/12] INFO: Test paths: DnsTests.cs, Properties/AssemblyInfo.cs, packages.config [19:33:08][Step 12/12] INFO: Indexing files of module 'TestDeployIIS' [19:33:08][Step 12/12] INFO: Base dir: C:\TeamCity\buildAgent\work\d6fbb810286f4111\repo [19:33:08][Step 12/12] INFO: 6 files indexed

Linfar commented 5 years ago

You cannot use TeamCity parameters (%param%) in SonarQube UI - these are different systems. There is some parametrisation in SonarQube (like ${WORKSPACE}) but i'm not familiar with it so please check SonarQube documentation if you want to use it.

If you want to use SonarQube UI to configure analysis then perhaps relative paths are a good chose.