Include Code Quality for Bamboo
Breadcrumbs

Sonar™Scanner

Configuration

  1. Configure the Sonar™Scanner as described in the SonarQube™ Wiki.

    1. See the official Sonar™Scanner example projects for inspiration

  2. Add a Sonar™ Scanner task to your Bamboo job

  3. For test coverage in SonarQube™ with Sonar™Scanner, please pass the required parameters to specify the path to the coverage reports as described in the SonarQube™ Wiki.

How to use with Docker

  1. Define a remote agent capability for the Sonar™Scanner CLI Docker image:

    1. Go to Bamboo > Agents > Shared Remote Capabilities

    2. Create a new capability of type Custom with key docker-sq-scanner and value /opt/sonar-scanner

      image-20230728-140847.png
    3. Create a new Bamboo job for the SonarQube™ analysis and use the Docker image sonarsource/sonar-scanner-cli:latest:

      image-20230728-140318.png

      d. Add the Sonar™Scanner task configuration, and choose for the field SonarQube™Scanner executable the value docker-sq-scanner

      image-20240906-151016.png
    4. Run the Bamboo job, and the analysis should work fine.

    5. If you experience any errors like JGit Failed to find all committed files , make sure you follow the troubleshooting advice below.

Tips and Troubleshooting

Remote Agents

If you use SonarScanner task on a remote agent, set the capability by either

a) adding a SonarScanner capability to your remote agent in the Bamboo UI, see above

b) or add the following key/value pair to your bamboo-agent-home/bin/bamboo-capabilities.properties file, see Bamboo docs for more details:

  • system.builder.sos.SonarScanner=/path/to/your/sonarqube-scanner/home
    

SonarQube™ scanners need access to the full git repository. If you encounter issues, e.g. in a containerized build, ensure that you

  • uncheck "Use shallow clones" option (Fetches the shallowest commit history possible. Do not use if your build depends on full repository history)

  • check "Fetch whole repository" option (Fetches whole repository instead of only one branch)