How to obtain the sonar.pullrequest.key dynamically

I am setting PR decoration for my project and I am adding the following configuration in my :


However, the sonar.pullrequest.key I don’t want it to be static but every new PR the analysis for the PR decoration is performed.

I am using Docker to install, analyze with Sonar and AWS Codebuild as CI/CD.

How can I pass the most recent PR always?


Welcome to the community!

Those values are read from the environment in most cases. What happens if you don’t set them at all?


It seems that the sonar.pullrequest.key is mandatory, if I don’t set it, I get an error that I need it :frowning:

ERROR: Error during SonarScanner execution
ERROR: Parameter 'sonar.pullrequest.key' is mandatory for a pull request analysis
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Which ones do you mean not to set?


Sorry. I guess I was thinking about SonarQube.

So going back to your question, I don’t think variables are interpolated in But they probably will be on the analysis command line.

And, I still believe the data you need is likely to be in your env. So once you find the right variable name, you can do something like:

sonar-scanner -Dsonar.pullrequest.key=${pr-key-env-var}


Yes, correct, that was my initial question. How do I know what my pr-key-env-var is :frowning:


The bottom of the AWS docs tells you how to output your envvars.


Yes, I found a way by using the AWS Codebuild environment variables in this case and injecting it as an argument in my Dockerfile (since I am installing and running sonar there).

Thanks for your help @ganncamp!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.