Adds setting for branch analysis

This commit is contained in:
Mario Lubenka 2019-11-20 22:36:35 +01:00
parent 6c61395706
commit d0fc9a1d7f
4 changed files with 29 additions and 17 deletions

View File

@ -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

Binary file not shown.

22
main.go
View File

@ -82,6 +82,11 @@ func main() {
Value: "false",
EnvVar: "PLUGIN_SHOWPROFILING",
},
cli.BoolFlag{
Name: "branchAnalysis",
Usage: "execute branchAnalysis",
EnvVar: "PLUGIN_BRANCHANALYSIS",
},
}
app.Run(os.Args)
@ -95,14 +100,15 @@ func run(c *cli.Context) {
Host: c.String("host"),
Token: c.String("token"),
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"),
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"),
},
}

View File

@ -13,14 +13,15 @@ type (
Host string
Token string
Version string
Branch 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
@ -35,7 +36,6 @@ func (p Plugin) Exec() error {
"-Dsonar.login=" + p.Config.Token,
"-Dsonar.projectVersion=" + p.Config.Version,
"-Dsonar.branch.name=" + p.Config.Branch,
"-Dsonar.sources=" + p.Config.Sources,
"-Dsonar.ws.timeout=" + p.Config.Timeout,
"-Dsonar.inclusions=" + p.Config.Inclusions,
@ -44,6 +44,11 @@ func (p Plugin) Exec() error {
"-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()