Create SonarQube plugin procedures

5 minute readExtensibilityDeveloper productivity

Plugin procedures can be used in procedure steps, process steps, and pipeline tasks, allowing you to orchestrate third-party tools at the appropriate time in your component, application process, or pipeline.

CollectReportingData

Collects reporting data from SonarQube and sends it to the CloudBees CD/RO reporting server.

Input parameters

Table 1. CollectReportingData input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Preview mode

This mode is provided to let you perform a WHAT IF analysis before enabling automatic reporting. If selected, no metadata is set and reports are not sent to the reporting server. Instead, detailed information about each object retrieved from SonarQube that includes transformation, mapping, and payload, is included in the summary logs.

Project key

Required. The project key that is unique for each project in SonarQube.

File prefix

If provided, the matching string is removed from the file path before sending the report. For example, if the file path is /opt/repo/file1, file prefix = /opt/repo resolves to /file1. Similarly, file prefix = /opt/repo/ resolves to file1.

Field mapping

Allows you to place custom fields to the payload or modify payload values. For example, "MyApplication":codeQuality.releaseName maps the value "MyApplication" to the code_quality report’s releaseName field.

Transform script

Allows you to provide a Perl script for payload customization. This method is invoked by a plugin with two parameters. The first parameter is the context object and the second parameter is the payload object. Since EC-SonarQube-1.5.2.0 sends two types of reports, the payload is a hash reference with build and payload sections. The method should be named transform and should return the payload object. In this example, the myCustomField field is added to the codeQuality payload object and to each codeQualityFile payload object:

sub transform { my ($context, $payload) = @_; # $payload->{codeQuality}->{myCustomField} = 1; # for my $p (@{$payload->{codeQualityFile}}) { # $p->{myCustomField2} = 2; # } return $payload; } sub one { my ($context) = @_; return time(); }

Metadata property path

The property sheet where run metadata is stored. If omitted, /mySchedule/EC-SonarQube-%JobName%-%Report Object Type% is used for schedule context. For all other contexts, the root is /myProject.

Base URL for drill-down

The base URL for SonarQube. If empty, it is set to %url_from_configuration%/dashboard?id=%Project\Key%.

Debug

If selected, the summary logs are written with the highest verbosity for the entire procedure.

Get Last SonarQube Metrics

Retrieves the last metrics from SonarQube based on specified parameters.

Input parameters

Table 2. Get Last SonarQube Metrics input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Sonar task ID

The task ID that is passed to this procedure from the run of SonarScanner, initiated by third-party software. If it is set, this procedure waits for SonarQube to process the task, download analysis data, and process metrics. If this parameter is not passed, then only the metrics check for the specified SonarQube project is ran.

Project key

Required. The project key that is unique for each project in SonarQube.

Project name

Required. The name of the project that is displayed in the SonarQube web interface.

Project version

The project version in SonarQube.

Sonar timeout

The timeout, in minutes, to wait for the task to be completed. The default timeout is 60 minutes.

Type of stored result

Set the result property format.

Property to store results

Set the result property where run metadata is stored. If omitted, /myJob/getLastSonarMetrics is used.

Metrics: Complexity

The metrics to store. The options are All, New, or None.

Metrics: Documentation

The metrics to store. The options are All, New, or None.

Metrics: Duplications

The metrics to store. The options are All, New, or None.

Metrics: Issues

The metrics to store. The options are All, New, or None.

Metrics: Maintainability

The metrics to store. The options are All, New, or None.

Metrics: QualityGates

The metrics to store. The options are All, New, or None.

Metrics: Reliability

The metrics to store. The options are All, New, or None.

Metrics: Security

The metrics to store. The options are All, New, or None.

Metrics: General

The metrics to store. The options are All, New, or None.

Metrics: Tests

The metrics to store. The options are All, New, or None.

Initiate Scanning Process

Initiates a scanning process with specified parameters.

Input parameters

Table 3. Initiate Scanning Process input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Work directory

Set the working directory.

Source encoding

Set the source file encoding. For example, ISO-8859-1.

Project key

Required. The project key that is unique for each project in SonarQube.

Project name

Required. The name of the project that is displayed in the SonarQube web interface.

Project version

Required. The project version in SonarQube.

Local path to sources

Required. Comma-separated paths to directories that contain source files. For example, ./library, ./lib, ./gf_tool.pl.

Sonar timeout

The timeout, in minutes, to wait for the task to be completed. The default timeout is 60 minutes.

Custom values for SonarScanner

The SonarScanner custom settings. For example, "key=value" or new pair on each line, as in the common SonarScanner configuration.

Enable SonarScanner debug mode

Enable debug mode for SonarScanner.

Heap space (MB)

The heap size, in megabytes. For example, 512.

Set this property if you get Java heap space or java.lang.OutOfMemoryError errors on scanner run. SonarScanner retrieves this additional parameter via environment variable to prevent such errors.

Type of stored result

Set the result property format.

Property to store results

Set the result property where run metadata is stored. If omitted, /myJob/initiateScanner is used.

Run Sonar Scanner

Runs SonarQube Scanner with specified parameters.

Input parameters

Table 4. Run Sonar Scanner input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Work directory

Set the working directory.

Source encoding

Set the source file encoding. For example, ISO-8859-1.

Project key

Required. The project key that is unique for each project in SonarQube.

Project name

Required. The name of the project that is displayed in the SonarQube web interface.

Project version

Required. The project version in SonarQube.

Local path to sources

Required. Comma-separated paths to directories that contain source files. For example, ./library, ./lib, ./gf_tool.pl.

Sonar timeout

The timeout, in minutes, to wait for the task to be completed. The default timeout is 60 minutes.

Custom values for SonarScanner

The SonarScanner custom settings. For example, "key=value" or new pair on each line, like in the common SonarScanner configuration.

Enable SonarScanner debug mode

Enable debug mode for SonarScanner.

Heap space (MB)

The heap size, in megabytes. For example, 512. Set this property if you get Java heap space or java.lang.OutOfMemoryError errors on scanner run. SonarScanner retrieves this additional parameter via environment variable to prevent such errors.

Type of stored result

Set the result property format.

Property to store results

Set the result property where run metadata is stored. If omitted, /myJob/runSonarScanner is used.

Metrics: Complexity

The metrics to store. The options are All, New, or None.

Metrics: Documentation

The metrics to store. The options are All, New, or None.

Metrics: Duplications

The metrics to store. The options are All, New, or None.

Metrics: Issues

The metrics to store. The options are All, New, or None.

Metrics: Maintainability

The metrics to store. The options are All, New, or None.

Metrics: QualityGates

The metrics to store. The options are All, New, or None.

Metrics: Reliability

The metrics to store. The options are All, New, or None.

Metrics: Security

The metrics to store. The options are All, New, or None.

Metrics: General

The metrics to store. The options are All, New, or None.

Metrics: Tests

The metrics to store. The options are All, New, or None.