How to get pull request branch details dynamically in sonarcloud


I am looking for options to get the git pull request details dynamically when sonarcloud is integrated with teamcity.

Currently, I am passing the values directly using the parameters like -Dsonar.pullrequest.base=master -Dsonar.pullrequest.branch=sonar_test -Dsonar.pullrequest.key=2 -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=calculator

but I want these values to be pulled dynamically when any new pull request is happened in Github.

Please help…


Any help on this is highly appreciated :slight_smile:

We are working on the scanner auto-configuration thanks to introspection of the CI environment variables. The support of TeamCity is not planned yet. However just to check the feasibility, could you share the env variables that are available on your builds, for both regular builds and pull requests?


Hi Simon,

I am not using any env variables as of now… All I am using is sonar cmds which are provided by sonarcloud at the time of configuration… I am just checking how can these parameters be passed into the teamcity build job dynamically by storing these values in teamcity parameters…

As, of now all I got is the below…

mvn sonar:sonar -Dsonar.projectKey=ramiyerk_calculator -Dsonar.organization=ramiyerk-github -Dsonar.login=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -Dsonar.pullrequest.base=master -Dsonar.pullrequest.branch=sonar_test -Dsonar.pullrequest.key=8 -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=calculator"


sonar.pullrequest.github.repository should define both the GitHub organization and repository, so ramiyerk/calculator in your case.

Okay… What about the Pull Request branch and Pull Request Key ? How can I get those values dynamically. Because If I don’t provide those details… The teamcity build runs the job but in the SonarCloud it is not showing any information about the respective job for which I have not provided the Pull Request Key or branch name…


Can some one pls help me here ?