diff --git a/DOCS.md b/DOCS.md index 570d08e..884c4b3 100644 --- a/DOCS.md +++ b/DOCS.md @@ -60,6 +60,7 @@ Safety first, the host and token are stored in Drone Secrets. * DEBUG: Display INFO logs + more details at DEBUG level. * TRACE: Display DEBUG logs + the timings of all ElasticSearch queries and Web API calls executed by the SonarQube Scanner. * `showProfiling`: Display logs to see where the analyzer spends time. Default value `false` +* `branchAnalysis`: Pass currently analysed branch to SonarQube. (Must not be active for initial scan!) Default value `false` # Notes diff --git a/drone-sonar b/drone-sonar index dec2301..69cfba7 100755 Binary files a/drone-sonar and b/drone-sonar differ diff --git a/main.go b/main.go index d4f7af2..32b3b57 100755 --- a/main.go +++ b/main.go @@ -43,6 +43,11 @@ func main() { Usage: "Project version", EnvVar: "DRONE_BUILD_NUMBER", }, + cli.StringFlag{ + Name: "branch", + Usage: "Project branch", + EnvVar: "DRONE_BRANCH", + }, cli.StringFlag{ Name: "timeout", Usage: "Web request timeout", @@ -77,6 +82,11 @@ func main() { Value: "false", EnvVar: "PLUGIN_SHOWPROFILING", }, + cli.BoolFlag{ + Name: "branchAnalysis", + Usage: "execute branchAnalysis", + EnvVar: "PLUGIN_BRANCHANALYSIS", + }, } app.Run(os.Args) @@ -90,13 +100,15 @@ func run(c *cli.Context) { Host: c.String("host"), Token: c.String("token"), - Version: c.String("ver"), - Timeout: c.String("timeout"), - Sources: c.String("sources"), - Inclusions: c.String("inclusions"), - Exclusions: c.String("exclusions"), - Level: c.String("level"), - showProfiling: c.String("showProfiling"), + Version: c.String("ver"), + Branch: c.String("branch"), + Timeout: c.String("timeout"), + Sources: c.String("sources"), + Inclusions: c.String("inclusions"), + Exclusions: c.String("exclusions"), + Level: c.String("level"), + showProfiling: c.String("showProfiling"), + branchAnalysis: c.Bool("branchAnalysis"), }, } diff --git a/plugin.go b/plugin.go index 4602a2b..30338be 100755 --- a/plugin.go +++ b/plugin.go @@ -1,25 +1,27 @@ package main import ( - "strings" "fmt" "os/exec" + "strings" ) type ( Config struct { - Key string - Name string - Host string - Token string + Key string + Name string + Host string + Token string - Version string - Sources string - Timeout string - Inclusions string - Exclusions string - Level string - showProfiling string + Version string + Branch string + Sources string + Timeout string + Inclusions string + Exclusions string + Level string + showProfiling string + branchAnalysis bool } Plugin struct { Config Config @@ -41,8 +43,12 @@ func (p Plugin) Exec() error { "-Dsonar.log.level=" + p.Config.Level, "-Dsonar.showProfiling=" + p.Config.showProfiling, "-Dsonar.scm.provider=git", - } + + if p.Config.branchAnalysis { + args = append(args, "-Dsonar.branch.name="+p.Config.Branch) + } + cmd := exec.Command("sonar-scanner", args...) // fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput()