Skip to content

Commit ba31f11

Browse files
wait for quality gate param independency
1 parent 9f84f00 commit ba31f11

File tree

5 files changed

+39
-54
lines changed

5 files changed

+39
-54
lines changed

.drone.yml

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,27 @@ pool:
99
use: ubuntu
1010

1111
steps:
12-
- name: pr test java 11
13-
image: plugins/docker:20
14-
settings:
15-
daemon_off: false
16-
dockerfile: Dockerfile
17-
repo: plugins/sonarqube-scanner
18-
dry_run: true
19-
when:
20-
ref:
21-
- "refs/pull/**" # Only run for pull requests
2212
- name: pr test java 17
2313
image: plugins/docker:20
2414
settings:
2515
daemon_off: false
26-
dockerfile: DockerfileJava17
16+
dockerfile: Dockerfile
2717
repo: plugins/sonarqube-scanner
2818
dry_run: true
2919
when:
3020
ref:
3121
- "refs/pull/**" # Only run for pull requests
32-
# - name: publish
33-
# image: plugins/docker:18
34-
# settings:
35-
# auto_tag: true
36-
# auto_tag_suffix: linux-amd64
37-
# daemon_off: false
38-
# dockerfile: Dockerfile
39-
# password:
40-
# from_secret: docker_password
41-
# repo: plugins/sonarqube-scanner
42-
# username:
43-
# from_secret: docker_username
44-
# when:
45-
# ref:
46-
# - refs/heads/main
47-
# - refs/tags/**
48-
- name: publish-2.0.4-java17
22+
- name: publish-2.0.5-java17
4923
image: plugins/docker:20
5024
settings:
5125
# auto_tag: true
5226
# auto_tag_suffix: v2.0.2-java17
5327
tags:
54-
- v2.0.4-java17
55-
# - latest-java17
28+
- v2.0.5
29+
- latest
5630
# - stable-java17
5731
daemon_off: false
58-
dockerfile: DockerfileJava17
32+
dockerfile: Dockerfile
5933
password:
6034
from_secret: docker_password
6135
repo: plugins/sonarqube-scanner

Dockerfile

100755100644
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ RUN go get github.com/urfave/cli
1313
RUN go get github.com/joho/godotenv
1414
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o harness-sonar
1515

16-
FROM openjdk:11.0.16-jre
16+
FROM amazoncorretto:17.0.8-alpine3.18
1717

1818
ARG SONAR_VERSION=5.0.1.3006
1919
ARG SONAR_SCANNER_CLI=sonar-scanner-cli-${SONAR_VERSION}
2020
ARG SONAR_SCANNER=sonar-scanner-${SONAR_VERSION}
2121

22-
RUN apt-get update \
23-
&& apt-get install -y nodejs curl \
24-
&& apt-get clean
22+
# RUN apt-get update \
23+
# && apt-get install -y nodejs curl \
24+
# && apt-get clean
25+
26+
RUN apk --no-cache --update add nodejs curl unzip
2527

2628
COPY --from=build /go/src/github.com/diegopereiraeng/harness-cie-sonarqube-scanner/harness-sonar /bin/
2729
WORKDIR /bin

DockerfileJava17 renamed to Dockerfile_Deprecated

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ RUN go get github.com/urfave/cli
1313
RUN go get github.com/joho/godotenv
1414
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o harness-sonar
1515

16-
FROM amazoncorretto:17.0.8-alpine3.18
16+
FROM openjdk:11.0.16-jre
1717

1818
ARG SONAR_VERSION=5.0.1.3006
1919
ARG SONAR_SCANNER_CLI=sonar-scanner-cli-${SONAR_VERSION}
2020
ARG SONAR_SCANNER=sonar-scanner-${SONAR_VERSION}
2121

22-
# RUN apt-get update \
23-
# && apt-get install -y nodejs curl \
24-
# && apt-get clean
25-
26-
RUN apk --no-cache --update add nodejs curl unzip
22+
RUN apt-get update \
23+
&& apt-get install -y nodejs curl \
24+
&& apt-get clean
2725

2826
COPY --from=build /go/src/github.com/diegopereiraeng/harness-cie-sonarqube-scanner/harness-sonar /bin/
2927
WORKDIR /bin

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
var build = "1" // build number set at compile time
12+
1213
func main() {
1314
app := cli.NewApp()
1415
app.Name = "Drone-Sonar-Plugin"
@@ -249,6 +250,11 @@ func main() {
249250
Usage: "Skip the SonarQube scan",
250251
EnvVar: "PLUGIN_SKIP_SCAN",
251252
},
253+
cli.BoolTFlag{
254+
Name: "wait_qualitygate",
255+
Usage: "Wait for the SonarQube quality gate",
256+
EnvVar: "PLUGIN_WAIT_QUALITYGATE",
257+
},
252258
}
253259
app.Run(os.Args)
254260
}
@@ -295,6 +301,7 @@ func run(c *cli.Context) {
295301
CustomJvmParams: c.String("custom_jvm_params"),
296302
TaskId: c.String("taskid"),
297303
SkipScan: c.Bool("skip_scan"),
304+
WaitQualityGate: c.Bool("wait_qualitygate"),
298305
},
299306
Output: Output{
300307
OutputFile: c.String("output-file"),

plugin.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"net/url"
1515
"os"
1616
"os/exec"
17+
"strconv"
1718
"strings"
1819
"time"
1920

@@ -81,6 +82,7 @@ type (
8182
CustomJvmParams string
8283
TaskId string
8384
SkipScan bool
85+
WaitQualityGate bool
8486
}
8587
Output struct {
8688
OutputFile string // File where plugin output are saved
@@ -179,6 +181,8 @@ type AnalysisResponse struct {
179181
} `json:"analyses"`
180182
}
181183

184+
const lineBreak = "----------------------------------------------"
185+
182186
func init() {
183187
netClient = &http.Client{
184188
Timeout: time.Second * 10,
@@ -277,15 +281,15 @@ func displaySummary(total, passed, failed int, errors int, newErrors int, projec
277281
fmt.Println("Successfully closed .env file")
278282
fmt.Print("\n\n")
279283
// Display the table
280-
fmt.Println("----------------------------------------------")
284+
fmt.Println(lineBreak)
281285
fmt.Printf("| STATUS | COUNT |\n")
282-
fmt.Println("----------------------------------------------")
286+
fmt.Println(lineBreak)
283287
fmt.Printf("| (\033[32mPASSED\033[0m) | %d |\n", passed)
284-
fmt.Println("----------------------------------------------")
288+
fmt.Println(lineBreak)
285289
fmt.Printf("| (\033[31mFAILED\033[0m) | %d |\n", failed)
286-
fmt.Println("----------------------------------------------")
290+
fmt.Println(lineBreak)
287291
fmt.Printf("| TOTAL | %d |\n", total)
288-
fmt.Println("----------------------------------------------")
292+
fmt.Println(lineBreak)
289293
fmt.Printf("\n\nCategorization: %s\n", category)
290294
}
291295

@@ -402,7 +406,7 @@ func (p Plugin) Exec() error {
402406
"-Dsonar.showProfiling": p.Config.ShowProfiling,
403407
"-Dsonar.java.binaries": p.Config.Binaries,
404408
"-Dsonar.branch.name": p.Config.Branch,
405-
"-Dsonar.qualitygate.wait": p.Config.QualityEnabled,
409+
"-Dsonar.qualitygate.wait": strconv.FormatBool(p.Config.WaitQualityGate),
406410
"-Dsonar.qualitygate.timeout": p.Config.QualityTimeout,
407411
"-Dsonar.javascript.lcov.reportPaths": p.Config.JavascitptIcovReport,
408412
"-Dsonar.coverage.jacoco.xmlReportPaths": p.Config.JacocoReportPath,
@@ -694,17 +698,17 @@ func (p Plugin) Exec() error {
694698
}
695699

696700
func displayQualityGateStatus(status string, qualityEnabled bool) {
697-
fmt.Println("----------------------------------------------")
701+
fmt.Println(lineBreak)
698702
fmt.Printf("| QUALITY GATE STATUS REPORT |\n")
699-
fmt.Println("----------------------------------------------")
703+
fmt.Println(lineBreak)
700704

701705
if status == "OK" {
702706
fmt.Printf("| STATUS | \033[32m%s\033[0m |\n", status)
703707
} else {
704708
fmt.Printf("| STATUS | \033[31m%s\033[0m |\n", status)
705709
}
706710

707-
fmt.Println("----------------------------------------------")
711+
fmt.Println(lineBreak)
708712

709713
if qualityEnabled {
710714
fmt.Printf("| QUALITY GATE ENABLED | \033[32mYES\033[0m |\n")
@@ -713,9 +717,9 @@ func displayQualityGateStatus(status string, qualityEnabled bool) {
713717
}
714718

715719
fmt.Printf("----------------------------------------------\n\n")
716-
fmt.Println("----------------------------------------------")
720+
fmt.Println(lineBreak)
717721
fmt.Printf("| Developed by: Diego Pereira |\n")
718-
fmt.Println("----------------------------------------------")
722+
fmt.Println(lineBreak)
719723
}
720724

721725
func staticScan(p *Plugin) (*SonarReport, error) {
@@ -778,7 +782,7 @@ func getStatus(task *TaskResponse, report *SonarReport) string {
778782
// JUNUT
779783
junitReport := ""
780784
junitReport = string(buf) // returns a string of what was written to it
781-
fmt.Println("----------------------------------------------")
785+
fmt.Println(lineBreak)
782786
fmt.Printf("| SONAR SCAN + JUNIT EXPORTER PLUGIN |\n")
783787
fmt.Print("----------------------------------------------\n\n\n")
784788
bytesReport := []byte(junitReport)
@@ -794,7 +798,7 @@ func getStatus(task *TaskResponse, report *SonarReport) string {
794798
file, _ := xml.MarshalIndent(result, "", " ")
795799
_ = ioutil.WriteFile("sonarResults.xml", file, 0644)
796800

797-
fmt.Println("----------------------------------------------")
801+
fmt.Println(lineBreak)
798802
fmt.Printf("| Harness Drone/CIE SonarQube Plugin Results |\n")
799803
fmt.Print("----------------------------------------------\n\n\n")
800804

0 commit comments

Comments
 (0)