1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-10-30 23:57:50 +02:00

feat(sonar): add parameter to wait for Quality Gate (#4047)

This commit is contained in:
Christopher Fenner
2023-01-27 16:14:34 +01:00
committed by GitHub
parent 5de1c6a7c2
commit 0626c7d861
3 changed files with 21 additions and 0 deletions

View File

@@ -150,6 +150,9 @@ func runSonar(config sonarExecuteScanOptions, client piperhttp.Downloader, runne
if config.InferJavaBinaries && !isInOptions(config, javaBinaries) {
addJavaBinaries()
}
if config.WaitForQualityGate {
sonar.addOption("sonar.qualitygate.wait=true")
}
if err := handlePullRequest(config); err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err

View File

@@ -36,6 +36,7 @@ type sonarExecuteScanOptions struct {
InferJavaBinaries bool `json:"inferJavaBinaries,omitempty"`
InferJavaLibraries bool `json:"inferJavaLibraries,omitempty"`
Options []string `json:"options,omitempty"`
WaitForQualityGate bool `json:"waitForQualityGate,omitempty"`
BranchName string `json:"branchName,omitempty"`
InferBranchName bool `json:"inferBranchName,omitempty"`
ChangeID string `json:"changeId,omitempty"`
@@ -250,6 +251,7 @@ func addSonarExecuteScanFlags(cmd *cobra.Command, stepConfig *sonarExecuteScanOp
cmd.Flags().BoolVar(&stepConfig.InferJavaBinaries, "inferJavaBinaries", false, "Find the location of generated Java class files in all modules and pass the option `sonar.java.binaries to the sonar tool.")
cmd.Flags().BoolVar(&stepConfig.InferJavaLibraries, "inferJavaLibraries", false, "If the parameter `m2Path` is configured for the step `mavenExecute` in the general section of the configuration, pass it as option `sonar.java.libraries` to the sonar tool.")
cmd.Flags().StringSliceVar(&stepConfig.Options, "options", []string{}, "A list of options which are passed to the sonar-scanner.")
cmd.Flags().BoolVar(&stepConfig.WaitForQualityGate, "waitForQualityGate", false, "Whether the scan should wait for and consider the result of the quality gate.")
cmd.Flags().StringVar(&stepConfig.BranchName, "branchName", os.Getenv("PIPER_branchName"), "Non-Pull-Request only: Name of the SonarQube branch that should be used to report findings to. Automatically inferred from environment variables on supported orchestrators if `inferBranchName` is set to true.")
cmd.Flags().BoolVar(&stepConfig.InferBranchName, "inferBranchName", false, "Whether to infer the `branchName` parameter automatically based on the orchestrator-specific environment variable in runs of the pipeline.")
cmd.Flags().StringVar(&stepConfig.ChangeID, "changeId", os.Getenv("PIPER_changeId"), "Pull-Request only: The id of the pull-request. Automatically inferred from environment variables on supported orchestrators.")
@@ -423,6 +425,15 @@ func sonarExecuteScanMetadata() config.StepData {
Aliases: []config.Alias{{Name: "sonarProperties", Deprecated: true}},
Default: []string{},
},
{
Name: "waitForQualityGate",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
Type: "bool",
Mandatory: false,
Aliases: []config.Alias{},
Default: false,
},
{
Name: "branchName",
ResourceRef: []config.ResourceReference{},

View File

@@ -142,6 +142,13 @@ spec:
aliases:
- name: sonarProperties
deprecated: true
- name: waitForQualityGate
type: bool
description: "Whether the scan should wait for and consider the result of the quality gate."
scope:
- PARAMETERS
- STAGES
- STEPS
# Parameters for non-PR scans
- name: branchName
type: string