Skip to content

Commit 0abe228

Browse files
Merge pull request #63 from diegopereiraeng/main
java 17 support + error msg enhancement + docs
2 parents 25b773d + ab89b61 commit 0abe228

File tree

4 files changed

+86
-13
lines changed

4 files changed

+86
-13
lines changed

.drone.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ pool:
99
use: ubuntu
1010

1111
steps:
12-
- name: pr test
12+
- name: pr test java 11
1313
image: plugins/docker:20
1414
settings:
1515
daemon_off: false
1616
dockerfile: Dockerfile
1717
repo: plugins/sonarqube-scanner
1818
dry_run: true
19+
- name: pr test java 17
20+
image: plugins/docker:20
21+
settings:
22+
daemon_off: false
23+
dockerfile: DockerfileJava17
24+
repo: plugins/sonarqube-scanner
25+
dry_run: true
1926
# - name: publish
2027
# image: plugins/docker:18
2128
# settings:
@@ -32,11 +39,15 @@ steps:
3239
# ref:
3340
# - refs/heads/main
3441
# - refs/tags/**
35-
- name: publish-v2.0.1
42+
- name: publish-2.0.2-java11
3643
image: plugins/docker:20
3744
settings:
38-
auto_tag: true
39-
auto_tag_suffix: v2.0.1
45+
# auto_tag: true
46+
# auto_tag_suffix: v2.0.2-java11
47+
tags:
48+
- v2.0.2-java11
49+
- latest-java11
50+
- stable-java11
4051
daemon_off: false
4152
dockerfile: Dockerfile
4253
password:
@@ -48,6 +59,26 @@ steps:
4859
ref:
4960
- refs/heads/main
5061
- refs/tags/**
62+
- name: publish-2.0.2-java17
63+
image: plugins/docker:20
64+
settings:
65+
# auto_tag: true
66+
# auto_tag_suffix: v2.0.2-java17
67+
tags:
68+
- v2.0.2-java17
69+
- latest-java17
70+
- stable-java17
71+
daemon_off: false
72+
dockerfile: DockerfileJava17
73+
password:
74+
from_secret: docker_password
75+
repo: plugins/sonarqube-scanner
76+
username:
77+
from_secret: docker_username
78+
when:
79+
ref:
80+
- refs/heads/main
81+
- refs/tags/**
5182
trigger:
5283
ref:
5384
- refs/heads/main

DockerfileJava17

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM golang:1.20-alpine as build
2+
RUN apk add --no-cache --update git
3+
RUN mkdir -p /go/src/github.com/diegopereiraeng/harness-cie-sonarqube-scanner
4+
WORKDIR /go/src/github.com/diegopereiraeng/harness-cie-sonarqube-scanner
5+
COPY *.go ./
6+
COPY *.mod ./
7+
8+
RUN go env GOCACHE
9+
10+
RUN go get github.com/sirupsen/logrus
11+
RUN go get github.com/pelletier/go-toml/cmd/tomll
12+
RUN go get github.com/urfave/cli
13+
RUN go get github.com/joho/godotenv
14+
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o harness-sonar
15+
16+
FROM amazoncorretto:8-alpine3.17-jre
17+
18+
ARG SONAR_VERSION=5.0.1.3006
19+
ARG SONAR_SCANNER_CLI=sonar-scanner-cli-${SONAR_VERSION}
20+
ARG SONAR_SCANNER=sonar-scanner-${SONAR_VERSION}
21+
22+
# RUN apt-get update \
23+
# && apt-get install -y nodejs curl \
24+
# && apt-get clean
25+
26+
RUN apk --no-cache add nodejs curl unzip
27+
28+
COPY --from=build /go/src/github.com/diegopereiraeng/harness-cie-sonarqube-scanner/harness-sonar /bin/
29+
WORKDIR /bin
30+
31+
RUN curl https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${SONAR_SCANNER_CLI}.zip -so /bin/${SONAR_SCANNER_CLI}.zip
32+
RUN unzip ${SONAR_SCANNER_CLI}.zip \
33+
&& rm ${SONAR_SCANNER_CLI}.zip
34+
35+
ENV PATH $PATH:/bin/${SONAR_SCANNER}/bin
36+
37+
ENTRYPOINT /bin/harness-sonar

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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.
44

5-
## Main Features - 2.0.1
5+
## Main Features - v2.0.2-java17
66

77
- Execute SonarQube scans and handle the results
88
- Generate JUnit reports based on the scan results
@@ -20,7 +20,7 @@ This plugin is designed to run SonarQube scans and handle the results and conver
2020
identifier: run_sonar
2121
spec:
2222
connectorRef: account.DockerHubDiego
23-
image: plugins/sonarqube-scanner:2.0.1
23+
image: plugins/sonarqube-scanner:v2.0.2-java17
2424
reports:
2525
type: JUnit
2626
spec:
@@ -42,7 +42,7 @@ This plugin is designed to run SonarQube scans and handle the results and conver
4242
type: Plugin
4343
spec:
4444
connectorRef: <+input>
45-
image: plugins/sonarqube-scanner:2.0.1
45+
image: plugins/sonarqube-scanner:v2.0.2-java17
4646
reports:
4747
type: JUnit
4848
spec:
@@ -78,11 +78,11 @@ spec:
7878
```yaml
7979
- step:
8080
type: Plugin
81-
name: "Check Sonar "
82-
identifier: run_sonar
81+
name: "Check Sonar Quality Gate"
82+
identifier: check_sonar
8383
spec:
8484
connectorRef: account.DockerHubDiego
85-
image: plugins/sonarqube-scanner:2.0.1
85+
image: plugins/sonarqube-scanner:v2.0.2-java17
8686
reports:
8787
type: JUnit
8888
spec:
@@ -91,9 +91,9 @@ spec:
9191
privileged: false
9292
settings:
9393
sonar_host: https://sonarcloud.io
94-
sonar_token: 66778345cea1a31d817f0deee3daa7868c431433
95-
sonar_name: sonarqube-scanner
96-
sonar_key: sonarqube-scanner
94+
sonar_token: 66778345yourToken817f0deee3daa7868c431433
95+
sonar_name: sonar-project-name
96+
sonar_key: sonar-project-key
9797
skip_scan: true
9898
```
9999

plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ func GetLatestTaskID(sonarHost string, projectSlug string) (string, error) {
962962
defer resp.Body.Close()
963963

964964
if resp.StatusCode != http.StatusOK {
965+
if resp.StatusCode == http.StatusForbidden {
966+
fmt.Printf("\nError in Task discovery: %s\n", "Check your token permission - probably it does not have 'Browse' permission on the project")
967+
} else if resp.StatusCode == http.StatusUnauthorized {
968+
fmt.Printf("\nError in Task discovery: %s\n", "Invalid Credentials - your token is not valid")
969+
}
965970
return "", fmt.Errorf("HTTP request error. Status code: %d", resp.StatusCode)
966971
}
967972

0 commit comments

Comments
 (0)