SonarQube Resource for Concourse CI
Performs SonarQube analyses and tracks the state of SonarQube quality gates.
This resource works with SonarCloud and self-hosted instaces of SonarQube.
If you want to implement a real quality gate in your build pipeline, you might want to also use the concourse-sonarqube-qualitygate-task which can be used to break a build if certain quality goals (as reported by SonarQube) are not reached.
- A running SonarQube instance (this resource was tested on v6.5–v7.1, but it should work with every version of SonarQube ≥ v5.3)
- The base URL of your SonarQube server has to be configured correctly! Otherwise
the resource will be unable to fetch analysis results when invoking it's
Add a new resource type to your Concourse CI pipeline:
resource_types: - name: sonar-runner type: docker-image source: repository: cathive/concourse-sonarqube-resource tag: latest # For reproducible builds use a specific tag and don't rely on "latest".
host_url: Required. The address of the SonarQube instance, e.g. "https://sonarcloud.io/" (when using SonarCloud). Must end with a slash.
organization: The organization to be used when submitting stuff to a sonarqube instance. This field is required when using SonarCloud to perform the analysis of your code.
login: The login or authentication token of a SonarQube user with Execute Analysis permission. Can be left out if SonarQube instance does not require any authentication.
password: The password that goes with the sonar.login username. This should be left blank if an authentication token is being used.
maven_settings: Maven settings to be used when performing SonarQube analysis. Only used if the scanner_type during the out phase has been set to / determined to use Maven.
__debug: This flag is used to debug any problems that might occur when using the resource itself. It enables extra debug output on the console and sets the
-xflag during shell execution. It is usually not a good idea to set this flag to
truein a production environment, because it might leak passwords and access key credentials to the console where it might be accessed by unauthorized / anonymous users.
The resource implements all three actions (check, in and out). The analysis is triggered by the out action and check/in will be used to wait for the result of the analysis and pull in the project status. Tasks can use this information to break the build (if desired) if any of the criterias of the quality gate associated with a project are not met.
out: Trigger SonarQube analysis
project_path: Required Path to the resource that shall be analyzed. If the path contains a file called "sonar-project.properties" it will be picked up during analysis.
scanner_type: Type of scanner to be used. Possible values are:
auto(default) Uses the maven-Scanner if a pom.xml is found in the directory specified by sources, cli otherwise.
cliForces usage of the command line scanner, even if a Maven project object model (pom.xml) is found in the sources directory.
mavenForces usage of the Maven plugin to perform the scan.
project_key: Project key (default value is read from sonar-project.properties)
project_name: Project name (default value is read from sonar-project.properties)
project_description: Project description (default value is read from sonar-project.properties)
project_version: Project version (default value is read from sonar-project.properties)
project_version_file: File to be used to read the Project version. When this option has been specified, it has precedence over the
autodetect_branch_name: Try to figure out the branch automatically. This works if the
project_pathcontains recognized SCM metadata from a supported revision control system. (Currently: only Git is supported!)
branch_name: Name of the branch. Overrides
autodetect_branch_nameif it has been set.
branch_target: Name of the branch where you intend to merge your short-lived branch at the end of its life. If left blank, this defaults to the master branch. It can also be used while initializing a long-lived branch to sync the issues from a branch other than the Main Branch. (See Branch Plugin documentation for further details)
sources: A list of paths to directories containing source files.
tests: A list of paths to directories containing source files.
additional_properties: Optional object/dictionary that may contain any additional properties that one might want to pass when running the sonar-scanner.
additional_properties_file: Optional path to a file containing properties that should be passed to the sonar-scanner.
maven_settings_file: Path to a Maven settings file that shall be used. Only used if the scanner_type during has been set to / determined to use Maven. If the resource itself has a maven_settings configuration, this key will override it's value.
sonar_maven_plugin_version: sonar-maven-plugin version (default is empty and using the latest version)
in: Fetch result of SonarQube analysis
The action will place two JSON files into the resource's folder which are fetched from the SonarQube Web API:
- qualitygate_project_status.json Quality gate status of the compute engine task that was triggered by the resource during the out action. Format: https://next.sonarqube.com/sonarqube/web_api/api/qualitygates/project_status
- ce_task_info.json Information about the compute engine task that performed the analysis. Format: https://next.sonarqube.com/sonarqube/web_api/api/ce/task
The following example pipeline shows how to use the resource to break the build if a project doesn't meet the requirements of the associated quality gate.