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

"SonarQube Branches & Pull Requests" feature displays configuration logs more than once #82

Closed axel3rd closed 3 years ago

axel3rd commented 4 years ago

Currently, the header configuration log is displayed more than once (one by step in fact):

[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'
[13:01:16] SonarQube plugin detects pull-request, 'env.SONARQUBE_SCANNER_PARAMS' set with '{"sonar.pullrequest.key":"42","sonar.pullrequest.branch":"Foo bar","sonar.pullrequest.base":"master","sonar.pullrequest.provider":"github","sonar.pullrequest.github.repository":"foo/bar"}'

But log "SonarQube plugin detects [pull-request|branch], 'env.SONARQUBE_SCANNER_PARAMS' set with ..." is displayed 3 times ... I should understand why 😒

Fixed by Execute process once (and not 4 each steps). It was because ParametersPreprocessor is executed for each steps of build.

Initial implementation (#77) has not fixed the problem.


https://github.com/JetBrains/TeamCity.SonarQubePlugin/blob/eb0d53dad41183f7be56637a4a8f4863d2fdf3e7/sonar-plugin-server/src/main/java/jetbrains/buildserver/sonarplugin/buildfeatures/BranchesAndPullRequestsParametersPreprocessor.java#L42-L45

The code seems executed at same time => sysenv flag is not suffisant.

Adding a block synchronize is perhaps the solution. @Linfar : Is it tolerable in a ParametersPreprocessor ?

Linfar commented 4 years ago

Synchronization can only solve problems caused by several threads concurrently modifying a shared state. Here there is only one thread initializing AgentBuild so synchronization won't help. Since runParameters isn't used anyway then probably BranchesAndPullRequestsParametersPreprocessor could be rewritten to BuildStartContextProcessor?

axel3rd commented 4 years ago

I'm currently /OOO, but I will try to achieve that this month.

axel3rd commented 4 years ago

Historical link: commit 0b78ca0

axel3rd commented 3 years ago

Fixed by #84 (merged)