DeployNow
...
Advanced Deployment Options
CI/CD with GitHub Actions

SonarQube Action

Check the Quality Gate of your code with SonarQube to ensure your code meets your own quality standards before you release or deploy new features.

SonarQube is the leading product for Continuous Code Quality & Code Security. It supports most popular programming languages, including Java, JavaScript, TypeScript, C#, Python, C, C++, and many more.

Requirements

A previous step must have run an analysis on your code.

Read more information on how to analyze your code here

Usage

The workflow YAML file will usually look something like this:

YAML


Make sure to set up timeout-minutesproperty in your step, to avoid wasting action minutes per month (see above example).

When using this action with sonarsource/sonarqube-scan action or with C/C++ code analysis you don't have to provide scanMetadataReportFileinput, otherwise you should alter the location of it.

Typically, report metadata file for different scanners can vary and can be located in:

  • target/sonar/report-task.txt
  • build/sonar/report-task.txt
  • .sonarqube/out/.sonar/report-task.txt

Example usage:



YAML


Environment variables

  • SONAR_TOKENRequired this is the token used to authenticate access to SonarQube. You can read more about security tokens here. You can set the SONAR_TOKEN environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
  • SONAR_HOST_URLOptional this tells the scanner where SonarQube is hosted, otherwise it will get the one from the scan report. You can set the SONAR_HOST_URL environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
  • SONAR_ROOT_CERT – Holds an additional root certificate (in PEM format) that is used to validate the SonarQube server certificate. You can set the SONAR_ROOT_CERT environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
  • SET_SONAR_PROJECT_STATUS - Sets the metadata (quality gate status) of a project as the output. Check https://sonarcloud.io/web_api/api/qualitygates/project_status?deprecated=false&section=response for more details on the metadata that SonarQube server returns.