SonarQube plugin use cases

2 minute readExtensibilityDeveloper productivity

The following examples illustrate how you can use the SonarQube plugin in CloudBees CD/RO to:

Configure the SonarQube job to initiate analysis

You can use the Run Sonar Scanner plugin procedure to initiate analysis for the SonarQube plugin job. For more information, refer to Run Sonar Scanner.

Analysis data is saved for each run. All available SonarQube parameters depend on the list of installed plugins and can be checked in the log after the job runs:

Figure 1. Log file

Configure jobs

When your workflow launches, code is processed locally on the agent by SonarScanner in the Work directory. If this is an initial run or the configuration of your SonarQube server is changed, SonarScanner downloads all plugins from the SonarQube server. The job configuration provides all required parameters for the scanner to initiate an analysis.

Configure the SonarQube plugin in a pipeline

This example shows how to add tasks to a pipeline stage to trigger SonarScanner to initiate analysis.

To configure the SonarQube plugin in a pipeline:

  1. Create a new pipeline. For more information, refer to Create a pipeline.

  2. For the pipeline stage, add an EC-Git Clone task, to clone your repository into a Work directory.

  3. Add an EC-SonarQube Run Sonar Scanner task, to run as a task targeting the Work directory.

  4. Optionally, add an EC-FileOps Delete Directory task, to remove the Work directory.

    Pipeline stage with tasks
    Figure 2. Pipeline stage

    After fetching the code, the SonarQube plugin triggers SonarScanner to initiate analysis by checking the code in the Work directory against the given list of parameters. After the analysis runs, results are saved and can be used as gate parameters for follow-on steps.

Configure an exit gate

You can configure an exit gate to control when a pipeline can exit a stage and the approvals that are required. In this example, a custom exit gate is used to locate any open issues from Sonar.

Exit gate
Figure 3. Pipeline exit gate