SonarCloud Integration with AWS CodeBuild (& Docker)

  • ALM used: Bitbucket Cloud
  • CI system used: AWS CodeBuild with Docker
  • Languages of the repository: Javascript (Angular)
  • Error observed:
When running: docker run --rm -e SONAR_HOST_URL=$SONAR_URL -e SONAR_LOGIN=$SONAR_TOKEN -v $CODEBUILD_SRC_DIR:/usr/src sonarsource/sonar-scanner-cli  I get this error: ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.organization```

And when I try to add -D sonar.projectKey=myProjKey -D sonar.organization=myOrg(to the docker command, it doesn't work, I get this error: unknown shorthand flag: 'D' in -D)

How do I inject the missing parameters? (There is no info I can find about this in the documentation

Hi Magnus,

Welcome to the community support!

The space between the -D and the property key definition must be removed if I’m not mistaken:

-Dsonar.projectKey=myProjKey -Dsonar.organization=myOrg


Hi Olivier,

Thanks for the welcome! :slight_smile:

I get this error when change to your proposed solution:
unknown shorthand flag: ‘D’ in -Dsonar.projectKey=myProjectKey

from Docker I believe the error message is



Could try to run this command line (I mean the whole docker command) outside of the CodeBuild context?

Try to run the scanner CLI without Docker, then add Docker, then add CodeBuild.

When I have such problems I try to remove all layers on top of what I try to run to undersand wether the issue is in the command or in the layers which require some extra steps to make it work (char escaping, …).

I use a personal Pyhton CLI tool I built to wrap the Sonar Scanner CLI and I can confirm the -D syntax.
Here is an extract of the code :

 def __run(self):

    java_args = ''
    for key, value in self.__java_options.items():
        java_option = f'{key}={value} '
        java_args = java_args + java_option

    args = [

    if self.__debug:

    if not self.__scm_blame:

the args String is then executed by the OS.



I managed to solve it be generating the file using printf as the command prior to the docker command :slight_smile: i.e:
printf “sonar.projectKey=%s\nsonar.organization=myOrganization” “myProjectKey” >

Thanks for the help!