Skip to content

Commit e57c664

Browse files
feat: Update SonarQube plugin to v2.4.2
- Added new parameters `sonar_config_file`, `sonar_config_file_override`, and `quality_gate_error_exit_code` for enhanced configuration control. - Updated README and documentation to include new features and configuration options. - Improved parameter reference with detailed descriptions and examples.
1 parent 0c372dd commit e57c664

File tree

5 files changed

+266
-150
lines changed

5 files changed

+266
-150
lines changed

.drone.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ steps:
1919
when:
2020
ref:
2121
- "refs/pull/**" # Only run for pull requests
22-
- name: publish-2.4.1
22+
- name: publish-2.4.2
2323
image: plugins/docker:20
2424
settings:
2525
# auto_tag: true
2626
# auto_tag_suffix: v2.0.2-java17
2727
tags:
28-
- v2.4.1
29-
# - latest
30-
# - stable-java17
28+
- v2.4.2
29+
- latest
30+
- stable-java17
3131
daemon_off: false
3232
dockerfile: Dockerfile
3333
password:
@@ -39,6 +39,26 @@ steps:
3939
ref:
4040
- refs/heads/main
4141
- refs/tags/**
42+
- name: publish-2.4.2-java11
43+
image: plugins/docker:20
44+
settings:
45+
# auto_tag: true
46+
# auto_tag_suffix: v2.0.2-java17
47+
tags:
48+
- v2.4.2
49+
- latest-java11
50+
- stable-java11
51+
daemon_off: false
52+
dockerfile: Dockerfile_Deprecated
53+
password:
54+
from_secret: docker_password
55+
repo: plugins/sonarqube-scanner
56+
username:
57+
from_secret: docker_username
58+
when:
59+
ref:
60+
- refs/heads/main
61+
- refs/tags/**
4262
trigger:
4363
ref:
4464
- refs/heads/main

DOCS.md

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,55 @@ steps:
2525
2626
Customized parameters could be specified:
2727
28-
```diff
29-
steps:
30-
- name: code-analysis
31-
image: drone-plugins/sonarqube-scanner
32-
settings:
33-
sonar_host:
34-
from_secret: sonar_host
35-
sonar_token:
36-
from_secret: sonar_token
37-
sonar_name: project-harness
38-
sonar_key: project-harness
39-
+ build_number: 1.0
40-
+ timeout: 20
41-
+ sources: .
42-
+ level: DEBUG
43-
+ showProfiling: true
44-
+ exclusions: **/static/**/*,**/dist/**/*.js
45-
+ usingProperties: false
46-
+ binaries: .
28+
```yaml
29+
steps:
30+
- name: code-analysis
31+
image: drone-plugins/sonarqube-scanner
32+
settings:
33+
sonar_host:
34+
from_secret: sonar_host
35+
sonar_token:
36+
from_secret: sonar_token
37+
sonar_name: project-harness
38+
sonar_key: project-harness
39+
build_number: 1.0
40+
timeout: 20
41+
sources: .
42+
level: DEBUG
43+
showProfiling: true
44+
exclusions: **/static/**/*,**/dist/**/*.js
45+
usingProperties: false
46+
binaries: .
47+
sonar_config_file: true
48+
sonar_config_file_override: false
49+
quality_gate_error_exit_code: 5
50+
sonar_qualitygate_timeout: 300
51+
branch: master
52+
inclusions: "*.go, *.java"
53+
sonar_quality_enabled: true
54+
artifact_file: artifact.json
55+
javascript_icov_reportPath: /path/to/icov/report
56+
java_coverage_plugin: jacoco
57+
jacoco_report_path: /path/to/jacoco/report
58+
ssl_keystore_pwd: your-keystore-password
59+
cacerts_location: /path/to/cacerts
60+
junit_reportpaths: /path/to/junit/reports
61+
source_encoding: UTF-8
62+
tests: /path/to/tests
63+
java_test: /path/to/java/test
64+
pr_key: 123
65+
pr_branch: your-pr-branch
66+
pr_base: your-pr-base
67+
coverage_exclusion: **/test/**/*.*,**/*.test.go
68+
java_source: 1.8
69+
java_libraries: /path/to/libraries
70+
surefire_reportsPath: /path/to/surefire/reports
71+
typescript_lcov_reportPaths: /path/to/typescript/lcov/reports
72+
verbose: true
73+
custom_jvm_params: "-Dsonar.java.source='value_you_want'"
74+
taskid: your-task-id
75+
skip_scan: true
76+
SONAR_SCANNER_OPTS: "--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED"
4777
```
4878
4979
# Secret Reference
@@ -52,48 +82,37 @@ Safety first, the host and token are stored in Drone Secrets.
5282
* `sonar_host`: Host of SonarQube with schema(http/https).
5383
* `sonar_token`: User token used to post the analysis report to SonarQube Server. Click User -- My Account -- Security -- Generate Tokens.
5484

55-
5685
# Parameter Reference
5786

58-
* `sonar_name`: Sonar Project NAme.
87+
* `sonar_name`: Sonar Project Name.
5988
* `sonar_key`: Sonar Project Key.
6089
* `sonar_qualitygate_timeout`: Timeout in seconds for Sonar Scan.
61-
* `artifact_file`: Timeout in seconds for Sonar Scan.
62-
* `sonar_quality_enabled`: True to block pipeline if sonar quality gate conditions are not met.
90+
* `artifact_file`: Path to the artifact file that will be generated by the plugin.
91+
* `sonar_quality_enabled`: True to block the pipeline if Sonar quality gate conditions are not met.
6392
* `branch`: Branch for analysis. (-Dsonar.branch.name=)
6493
* `build_number`: Build Version.
65-
6694
* `build_version`: Code version, Default value `DRONE_BUILD_NUMBER`.
67-
* `timeout`: Default seconds `60`.
68-
* `sources`: Comma-separated paths to directories containing source files.
69-
* `inclusions`: Comma-delimited list of file path patterns to be included in analysis. When set, only files matching the paths set here will be included in analysis.
95+
* `timeout`: Timeout in seconds, default `60`.
96+
* `sources`: Comma-separated paths to directories containing source files.
97+
* `inclusions`: Comma-delimited list of file path patterns to be included in analysis. Example: `*.go, *.java`.
7098
* `exclusions`: Comma-delimited list of file path patterns to be excluded from analysis. Example: `**/static/**/*,**/dist/**/*.js`.
71-
* `level`: Control the quantity / level of logs produced during an analysis. Default value `INFO`.
72-
* DEBUG: Display INFO logs + more details at DEBUG level.
73-
* TRACE: Display DEBUG logs + the timings of all ElasticSearch queries and Web API calls executed by the SonarQube Scanner.
99+
* `level`: Control the quantity/level of logs produced during an analysis. Default value `INFO`. Options are `DEBUG` and `TRACE`.
74100
* `showProfiling`: Display logs to see where the analyzer spends time. Default value `false` (-Dsonar.showProfiling=)
75-
* `branchAnalysis`: Pass currently analysed branch to SonarQube. (Must not be active for initial scan!) Default value `false`
76-
77-
78-
* `usingProperties`: Using the `sonar-project.properties` file in root directory as sonar parameters. (Not include `sonar_host` and
79-
`sonar_token`.) Default value `false`
80-
81-
* `sonar_qualitygate_timeout`: Quality gate timeout. (-Dsonar.qualitygate.timeout=)
82-
83-
* `binaries`: app binaries (-Dsonar.java.binaries=)
84-
101+
* `branchAnalysis`: Pass currently analyzed branch to SonarQube. (Must not be active for initial scan!) Default value `false`.
102+
* `usingProperties`: Use the `sonar-project.properties` file in the root directory as sonar parameters. (Not including `sonar_host` and `sonar_token`.) Default value `false`.
103+
* `binaries`: Path to application binaries (-Dsonar.java.binaries=).
104+
* `sonar_config_file`: Use `sonar-project.properties` if available. Default value `false`.
105+
* `sonar_config_file_override`: Use `sonar-project.properties` if available and override host, login, or project key settings. Default value `false`.
106+
* `quality_gate_error_exit_code`: Specifies the "exit code" error when the quality gate fails. Default is `5`.
85107

86108
# Javascript Parameters
87109

88-
* `javascript_icov_reportPath`: Path to coverage report (-Dsonar.javascript.lcov.reportPath)
89-
110+
* `javascript_icov_reportPath`: Path to coverage report (-Dsonar.javascript.lcov.reportPath).
90111

91112
# Java Parameters
92113

93-
* `jacoco_report_path`: Path to Jacoco Report (if not default). (-Dsonar.jacoco.reportPath=)
94-
95-
* `java_coverage_plugin`: plugin to use as coverage. ex: jacoco (-Dsonar.java.coveragePlugin=)
96-
114+
* `jacoco_report_path`: Path to Jacoco Report (if not default). (-Dsonar.jacoco.reportPath=).
115+
* `java_coverage_plugin`: Plugin to use as coverage, e.g., jacoco (-Dsonar.java.coveragePlugin=).
97116

98117
# Notes
99118

@@ -102,7 +121,7 @@ Safety first, the host and token are stored in Drone Secrets.
102121
* You could also add a file named `sonar-project.properties` at the root of your project to specify parameters.
103122

104123
Code repository: [drone-plugins/sonarqube-scanner](https://github.com/drone-plugins/sonarqube-scanner).
105-
SonarQube Parameters: [Analysis Parameters](https://docs.sonarqube.org/display/SONAR/Analysis+Parameters)
124+
SonarQube Parameters: [Analysis Parameters](https://docs.sonarqube.org/display/SONAR/Analysis+Parameters).
106125

107126
# Test your SonarQube Server:
108127

README.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
21
# Harness Drone/CIE SonarQube Plugin with Quality Gate
32

4-
This plugin is designed to run SonarQube scans and handle the results and convert it to JUnit Format. It's written in Go and check the report results for status OK.
3+
This plugin is designed to run SonarQube scans, handle the results, and convert them to JUnit format. It's written in Go and checks the report results for status OK.
4+
5+
## Main Features - v2.4.2
6+
7+
- **New Parameter: `sonar_config_file`**
8+
- **Type**: Boolean
9+
- **Description**: If set to true, the plugin will utilize the specified `sonar-project.properties` file for the SonarQube analysis, if it exists.
10+
- **Environment Variable**: `PLUGIN_SONAR_CONFIG_FILE`
11+
- **Allowed Values**: `"true"`, `"false"`
12+
13+
- **New Parameter: `sonar_config_file_override`**
14+
- **Type**: Boolean
15+
- **Description**: If set to true, the plugin will use the `sonar-project.properties` file and allow overriding of host, login, and/or project key settings.
16+
- **Environment Variable**: `PLUGIN_SONAR_CONFIG_FILE_OVERRIDE`
17+
- **Allowed Values**: `"true"`, `"false"`
18+
19+
- **New Parameter: `quality_gate_error_exit_code`**
20+
- **Type**: Integer
21+
- **Description**: Specifies the "exit code" error when the quality gate fails. Default is `5`.
22+
- **Environment Variable**: `PLUGIN_QUALITY_GATE_ERROR_EXIT_CODE`
23+
- **Default Value**: `5`
524

625
## Main Features - v2.4.1
726

827
- Sonar CLI downgraded from 6.0.0.4432 to 5.0.1.3006
928
- Execute SonarQube scans and handle the results
1029
- Generate JUnit reports based on the scan results
1130
- Quality Gate status reporting + Metrics
12-
- Skip Scan and only check for quality Gate Status of a specific analysisId or last analysis
13-
- Waiting for Analysis and QualityGate nows skip the wait if set to false - thanks @kangguru
14-
- Added SONAR_SCANNER_OPTS as param, so it transform into this env var during execution for Sonar JVM params - check for the param detail section below
31+
- Skip Scan and only check for Quality Gate status of a specific `analysisId` or last analysis
32+
- Waiting for Analysis and QualityGate now skips the wait if set to false - thanks @kangguru
33+
- Added `SONAR_SCANNER_OPTS` as a parameter, transforming into this env var during execution for Sonar JVM params - check the parameter detail section below
1534

16-
Obs: USe branch and pr_key params for accuracy results matches when skiping the scan
35+
**Note**: Use `branch` and `pr_key` parameters for accurate results matching when skipping the scan.
36+
37+
![Results](https://github.com/drone-plugins/sonarqube-scanner/blob/main/sonar-result-v2.png)
1738

18-
<img src="https://github.com/drone-plugins/sonarqube-scanner/blob/main/sonar-result-v2.png" alt="Results" width="800"/>
1939

2040
### Simple Pipeline example
2141

@@ -26,7 +46,7 @@ Obs: USe branch and pr_key params for accuracy results matches when skiping the
2646
identifier: run_sonar
2747
spec:
2848
connectorRef: account.DockerHubDiego
29-
image: plugins/sonarqube-scanner:v2.4.1
49+
image: plugins/sonarqube-scanner:v2.4.2
3050
reports:
3151
type: JUnit
3252
spec:
@@ -48,7 +68,7 @@ Obs: USe branch and pr_key params for accuracy results matches when skiping the
4868
type: Plugin
4969
spec:
5070
connectorRef: <+input>
51-
image: plugins/sonarqube-scanner:v2.4.1
71+
image: plugins/sonarqube-scanner:v2.4.2
5272
reports:
5373
type: JUnit
5474
spec:
@@ -88,7 +108,7 @@ spec:
88108
identifier: check_sonar
89109
spec:
90110
connectorRef: account.DockerHubDiego
91-
image: plugins/sonarqube-scanner:v2.4.1
111+
image: plugins/sonarqube-scanner:v2.4.2
92112
reports:
93113
type: JUnit
94114
spec:
@@ -110,7 +130,7 @@ name: default
110130

111131
steps:
112132
- name: perform-code-analysis
113-
image: plugins/sonarqube-scanner:v2.4.1
133+
image: plugins/sonarqube-scanner:v2.4.2
114134
settings:
115135
sonar_host: http://34.100.11.50
116136
sonar_token:
@@ -212,6 +232,24 @@ steps:
212232
- `SONAR_SCANNER_OPTS`: pass any Sonar JVM param as env var during execution.
213233
- Example: `"SONAR_SCANNER_OPTS": "--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED"`
214234

235+
- **`sonar_config_file`**:
236+
- **Type**: Boolean
237+
- **Description**: Use `sonar-project.properties` if available.
238+
- **Environment Variable**: `PLUGIN_SONAR_CONFIG_FILE`
239+
- **Allowed Values**: `"true"`, `"false"`
240+
241+
- **`sonar_config_file_override`**:
242+
- **Type**: Boolean
243+
- **Description**: Use `sonar-project.properties` if available and allow overriding of host, login, and/or project key settings.
244+
- **Environment Variable**: `PLUGIN_SONAR_CONFIG_FILE_OVERRIDE`
245+
- **Allowed Values**: `"true"`, `"false"`
246+
247+
- **`quality_gate_error_exit_code`**:
248+
- **Type**: Integer
249+
- **Description**: Specifies the "exit code" error when the quality gate fails. Default is `5`.
250+
- **Environment Variable**: `PLUGIN_QUALITY_GATE_ERROR_EXIT_CODE`
251+
- **Default Value**: `5`
252+
215253
Detail Informations/tutorials Parameteres: [DOCS.md](DOCS.md).
216254

217255
### Build Process

0 commit comments

Comments
 (0)