Skip to content

Commit 3c26b8f

Browse files
Update Dockerfile and .drone.yml, add workspace flag and fixed dashboard link
1 parent 7f0d031 commit 3c26b8f

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

.drone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ steps:
1919
when:
2020
ref:
2121
- "refs/pull/**" # Only run for pull requests
22-
- name: publish-2.1.3
22+
- name: publish-2.2.0
2323
image: plugins/docker:20
2424
settings:
2525
# auto_tag: true
2626
# auto_tag_suffix: v2.0.2-java17
2727
tags:
28-
- v2.1.3-sonar-4.6.2.2472
28+
- v2.2.0
2929
# - latest
3030
# - stable-java17
3131
daemon_off: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o harness-sonar
1515

1616
FROM amazoncorretto:17.0.8-alpine3.18
1717

18-
ARG SONAR_VERSION=4.6.2.2472
18+
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

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ func main() {
261261
Usage: "Wait for the SonarQube quality gate",
262262
EnvVar: "PLUGIN_WAIT_QUALITYGATE",
263263
},
264+
cli.StringFlag{
265+
Name: "workspace",
266+
Usage: "sonar workspace execution",
267+
Value: "/harness",
268+
EnvVar: "PLUGIN_WORKSPACE",
269+
},
264270
}
265271
app.Run(os.Args)
266272
}
@@ -308,6 +314,7 @@ func run(c *cli.Context) {
308314
TaskId: c.String("taskid"),
309315
SkipScan: c.Bool("skip_scan"),
310316
WaitQualityGate: c.Bool("wait_qualitygate"),
317+
Workspace: c.String("workspace"),
311318
},
312319
Output: Output{
313320
OutputFile: c.String("output-file"),

plugin.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535

3636
// sonarDashStatic is a static string used in the dashboard URL.
3737
sonarDashStatic = "/dashboard?id="
38-
38+
//https://sonar.dfinsolutions.com/dashboard?id=dfinsolutions_Saturn-UI_AYezvlRKNrcjU-xpGTBl&pullRequest=1244
3939
// basicAuth is the basic authentication string.
4040
basicAuth = "Basic "
4141
)
@@ -88,6 +88,7 @@ type (
8888
TaskId string
8989
SkipScan bool
9090
WaitQualityGate bool
91+
Workspace string
9192
}
9293
Output struct {
9394
OutputFile string // File where plugin output are saved
@@ -346,6 +347,11 @@ func ParseJunit(projectArray Project, projectName string) Testsuites {
346347
os.Setenv("SONAR_RESULT_OVERALL_ERRORS", fmt.Sprintf("%d", errors)) // Set the number of errors as an environment variable
347348

348349
dashboardLink := os.Getenv("PLUGIN_SONAR_HOST") + sonarDashStatic + os.Getenv("PLUGIN_SONAR_KEY")
350+
if os.Getenv("PLUGIN_PR_KEY") != "" {
351+
dashboardLink = os.Getenv("PLUGIN_SONAR_HOST") + sonarDashStatic + os.Getenv("PLUGIN_SONAR_KEY") + "&pullRequest=" + os.Getenv("PLUGIN_PR_KEY")
352+
} else if os.Getenv("PLUGIN_BRANCHANALYSIS") == "true" {
353+
dashboardLink = os.Getenv("PLUGIN_SONAR_HOST") + sonarDashStatic + os.Getenv("PLUGIN_SONAR_KEY") + "&branch=" + os.Getenv("PLUGIN_BRANCH")
354+
}
349355
SonarJunitReport := &Testsuites{
350356
TestSuite: []Testsuite{
351357
Testsuite{
@@ -468,6 +474,10 @@ func (p Plugin) Exec() error {
468474
args = append(args, params...)
469475
}
470476

477+
if len(p.Config.Workspace) >= 1 {
478+
args = append(args, "-Dsonar.projectBaseDir="+p.Config.Workspace)
479+
}
480+
471481
// Assuming your struct has a print or log method
472482
if len(p.Config.JacocoReportPath) >= 1 {
473483
fmt.Printf("\n\n==> Sonar Java Plugin Jacoco configured!\n\n")

0 commit comments

Comments
 (0)