Merge pull request #8 from saitho/feature/branch-configuration
Pass branch name to Sonar
This commit is contained in:
commit
8738de3efa
1
DOCS.md
1
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.
|
* 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.
|
* 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`
|
* `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
|
# Notes
|
||||||
|
|
||||||
|
BIN
drone-sonar
BIN
drone-sonar
Binary file not shown.
12
main.go
12
main.go
@ -43,6 +43,11 @@ func main() {
|
|||||||
Usage: "Project version",
|
Usage: "Project version",
|
||||||
EnvVar: "DRONE_BUILD_NUMBER",
|
EnvVar: "DRONE_BUILD_NUMBER",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "branch",
|
||||||
|
Usage: "Project branch",
|
||||||
|
EnvVar: "DRONE_BRANCH",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "timeout",
|
Name: "timeout",
|
||||||
Usage: "Web request timeout",
|
Usage: "Web request timeout",
|
||||||
@ -77,6 +82,11 @@ func main() {
|
|||||||
Value: "false",
|
Value: "false",
|
||||||
EnvVar: "PLUGIN_SHOWPROFILING",
|
EnvVar: "PLUGIN_SHOWPROFILING",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "branchAnalysis",
|
||||||
|
Usage: "execute branchAnalysis",
|
||||||
|
EnvVar: "PLUGIN_BRANCHANALYSIS",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
@ -91,12 +101,14 @@ func run(c *cli.Context) {
|
|||||||
Token: c.String("token"),
|
Token: c.String("token"),
|
||||||
|
|
||||||
Version: c.String("ver"),
|
Version: c.String("ver"),
|
||||||
|
Branch: c.String("branch"),
|
||||||
Timeout: c.String("timeout"),
|
Timeout: c.String("timeout"),
|
||||||
Sources: c.String("sources"),
|
Sources: c.String("sources"),
|
||||||
Inclusions: c.String("inclusions"),
|
Inclusions: c.String("inclusions"),
|
||||||
Exclusions: c.String("exclusions"),
|
Exclusions: c.String("exclusions"),
|
||||||
Level: c.String("level"),
|
Level: c.String("level"),
|
||||||
showProfiling: c.String("showProfiling"),
|
showProfiling: c.String("showProfiling"),
|
||||||
|
branchAnalysis: c.Bool("branchAnalysis"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
plugin.go
10
plugin.go
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -14,12 +14,14 @@ type (
|
|||||||
Token string
|
Token string
|
||||||
|
|
||||||
Version string
|
Version string
|
||||||
|
Branch string
|
||||||
Sources string
|
Sources string
|
||||||
Timeout string
|
Timeout string
|
||||||
Inclusions string
|
Inclusions string
|
||||||
Exclusions string
|
Exclusions string
|
||||||
Level string
|
Level string
|
||||||
showProfiling string
|
showProfiling string
|
||||||
|
branchAnalysis bool
|
||||||
}
|
}
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
Config Config
|
Config Config
|
||||||
@ -41,8 +43,12 @@ func (p Plugin) Exec() error {
|
|||||||
"-Dsonar.log.level=" + p.Config.Level,
|
"-Dsonar.log.level=" + p.Config.Level,
|
||||||
"-Dsonar.showProfiling=" + p.Config.showProfiling,
|
"-Dsonar.showProfiling=" + p.Config.showProfiling,
|
||||||
"-Dsonar.scm.provider=git",
|
"-Dsonar.scm.provider=git",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.Config.branchAnalysis {
|
||||||
|
args = append(args, "-Dsonar.branch.name="+p.Config.Branch)
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("sonar-scanner", args...)
|
cmd := exec.Command("sonar-scanner", args...)
|
||||||
// fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " "))
|
// fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " "))
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
Loading…
Reference in New Issue
Block a user