fix: support sonar-project.Properties
This commit is contained in:
parent
15157105c5
commit
c0971c7f44
2
.gitignore
vendored
2
.gitignore
vendored
@ -14,4 +14,4 @@
|
||||
.history
|
||||
.vscode
|
||||
.scannerwork
|
||||
|
||||
.idea
|
||||
|
38
DOCS.md
38
DOCS.md
@ -13,33 +13,34 @@ This plugin can scan your code quality and post the analysis report to your Sona
|
||||
The below pipeline configuration demonstrates simple usage:
|
||||
|
||||
```yaml
|
||||
steps
|
||||
steps:
|
||||
- name: code-analysis
|
||||
image: aosapps/drone-sonar-plugin
|
||||
settings:
|
||||
sonar_host:
|
||||
from_secret: sonar_host
|
||||
sonar_token:
|
||||
from_secret: sonar_token
|
||||
sonar_host:
|
||||
from_secret: sonar_host
|
||||
sonar_token:
|
||||
from_secret: sonar_token
|
||||
```
|
||||
|
||||
Customized parameters could be specified:
|
||||
|
||||
```diff
|
||||
steps
|
||||
steps:
|
||||
- name: code-analysis
|
||||
image: aosapps/drone-sonar-plugin
|
||||
settings:
|
||||
sonar_host:
|
||||
from_secret: sonar_host
|
||||
sonar_token:
|
||||
from_secret: sonar_token
|
||||
+ ver: 1.0
|
||||
+ timeout: 20
|
||||
+ sources: .
|
||||
+ level: DEBUG
|
||||
+ showProfiling: true
|
||||
+ exclusions: **/static/**/*,**/dist/**/*.js
|
||||
sonar_host:
|
||||
from_secret: sonar_host
|
||||
sonar_token:
|
||||
from_secret: sonar_token
|
||||
+ ver: 1.0
|
||||
+ timeout: 20
|
||||
+ sources: .
|
||||
+ level: DEBUG
|
||||
+ showProfiling: true
|
||||
+ exclusions: **/static/**/*,**/dist/**/*.js
|
||||
+ usingProperties: false
|
||||
```
|
||||
|
||||
# Secret Reference
|
||||
@ -62,6 +63,11 @@ Safety first, the host and token are stored in Drone Secrets.
|
||||
* `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`
|
||||
|
||||
|
||||
* `usingProperties`: Using the `sonar-project.properties` file in root directory as sonar parameters. (Not include `sonar_host` and
|
||||
`sonar_token`.) Default value `false`
|
||||
|
||||
|
||||
# Notes
|
||||
|
||||
* projectKey: `DRONE_REPO`
|
||||
|
11
main.go
11
main.go
@ -87,6 +87,11 @@ func main() {
|
||||
Usage: "execute branchAnalysis",
|
||||
EnvVar: "PLUGIN_BRANCHANALYSIS",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "usingProperties",
|
||||
Usage: "using sonar-project.properties",
|
||||
EnvVar: "PLUGIN_USINGPROPERTIES",
|
||||
},
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
@ -107,8 +112,10 @@ func run(c *cli.Context) {
|
||||
Inclusions: c.String("inclusions"),
|
||||
Exclusions: c.String("exclusions"),
|
||||
Level: c.String("level"),
|
||||
showProfiling: c.String("showProfiling"),
|
||||
branchAnalysis: c.Bool("branchAnalysis"),
|
||||
ShowProfiling: c.String("showProfiling"),
|
||||
BranchAnalysis: c.Bool("branchAnalysis"),
|
||||
UsingProperties: c.Bool("usingProperties"),
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
37
plugin.go
37
plugin.go
@ -20,8 +20,9 @@ type (
|
||||
Inclusions string
|
||||
Exclusions string
|
||||
Level string
|
||||
showProfiling string
|
||||
branchAnalysis bool
|
||||
ShowProfiling string
|
||||
BranchAnalysis bool
|
||||
UsingProperties bool
|
||||
}
|
||||
Plugin struct {
|
||||
Config Config
|
||||
@ -30,23 +31,29 @@ type (
|
||||
|
||||
func (p Plugin) Exec() error {
|
||||
args := []string{
|
||||
"-Dsonar.projectKey=" + strings.Replace(p.Config.Key, "/", ":", -1),
|
||||
"-Dsonar.projectName=" + p.Config.Name,
|
||||
"-Dsonar.host.url=" + p.Config.Host,
|
||||
"-Dsonar.login=" + p.Config.Token,
|
||||
|
||||
"-Dsonar.projectVersion=" + p.Config.Version,
|
||||
"-Dsonar.sources=" + p.Config.Sources,
|
||||
"-Dsonar.ws.timeout=" + p.Config.Timeout,
|
||||
"-Dsonar.inclusions=" + p.Config.Inclusions,
|
||||
"-Dsonar.exclusions=" + p.Config.Exclusions,
|
||||
"-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)
|
||||
if !p.Config.UsingProperties {
|
||||
argsParameter := []string{
|
||||
"-Dsonar.projectKey=" + strings.Replace(p.Config.Key, "/", ":", -1),
|
||||
"-Dsonar.projectName=" + p.Config.Name,
|
||||
"-Dsonar.projectVersion=" + p.Config.Version,
|
||||
"-Dsonar.sources=" + p.Config.Sources,
|
||||
"-Dsonar.ws.timeout=" + p.Config.Timeout,
|
||||
"-Dsonar.inclusions=" + p.Config.Inclusions,
|
||||
"-Dsonar.exclusions=" + p.Config.Exclusions,
|
||||
"-Dsonar.log.level=" + p.Config.Level,
|
||||
"-Dsonar.showProfiling=" + p.Config.ShowProfiling,
|
||||
"-Dsonar.scm.provider=git",
|
||||
}
|
||||
args = append(args, argsParameter)
|
||||
}
|
||||
|
||||
|
||||
if p.Config.BranchAnalysis {
|
||||
args = append(args, "-Dsonar.branch.name=" + p.Config.Branch)
|
||||
}
|
||||
|
||||
cmd := exec.Command("sonar-scanner", args...)
|
||||
|
Loading…
Reference in New Issue
Block a user