I am working on integration of BitBucket, TeamCity and SonarQube. My scenario is as follows:
TeamCity starts building the PR automatically;TeamCity posts the analysis results to SonarQube via SonarQube Runner with -Dsonar.branch.name=%teamcity.build.branch%;BitBucket requests the analysis details from SonarQube by the branch name and displays them on the PR page.So the problem is that I cannot deduce the name of the branch the PR is based on. Here is what happens:
TeamCity to listen to the +:refs/pull-requests/*/from reference in the VCS branch specification;TeamCity discovers a new PR it starts a buildteamcity.build.branch) gets to be equal to the number of the PR (because of the asterisk in the reference);BitBucket cannot retrieve the analysis details by the PR's branch name, because they are stored in SonarQube under the name which is equal to the number of the PR and not the name of the branch.Solution 1 (dynamic parameters):
SonarQube.Solution 2:
+:refs/pull-requests/*/from and +:refs/heads/*;VCS trigger that listens to +:refs/heads/* only;It does not seem like a good solution.
So it seems to me that the solution should be something like:
SonarQube Runner (-Dsonar.branch.name=%dynamic.branch...%)I read the documentation about TeamCity predefined branch parameters, but have not found anything helpful.
Please help me figure out how to config it.
By using a dedicated service message in your build script, you can dynamically update build parameters of the build right from a build step (the parameters need to be defined in the Parameters section of the build configuration).
Build Script Interaction with TeamCity
echo ##teamcity[setParameter name='ddd' value='fff']
P.S. echo is mandatory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With