github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/sonarExecuteScan_generated.go (about) 1 // Code generated by piper's step-generator. DO NOT EDIT. 2 3 package cmd 4 5 import ( 6 "fmt" 7 "os" 8 "path/filepath" 9 "reflect" 10 "strings" 11 "time" 12 13 "github.com/SAP/jenkins-library/pkg/config" 14 "github.com/SAP/jenkins-library/pkg/gcs" 15 "github.com/SAP/jenkins-library/pkg/log" 16 "github.com/SAP/jenkins-library/pkg/piperenv" 17 "github.com/SAP/jenkins-library/pkg/splunk" 18 "github.com/SAP/jenkins-library/pkg/telemetry" 19 "github.com/SAP/jenkins-library/pkg/validation" 20 "github.com/bmatcuk/doublestar" 21 "github.com/spf13/cobra" 22 ) 23 24 type sonarExecuteScanOptions struct { 25 Instance string `json:"instance,omitempty"` 26 Proxy string `json:"proxy,omitempty"` 27 ServerURL string `json:"serverUrl,omitempty"` 28 Token string `json:"token,omitempty"` 29 Organization string `json:"organization,omitempty"` 30 CustomTLSCertificateLinks []string `json:"customTlsCertificateLinks,omitempty"` 31 SonarScannerDownloadURL string `json:"sonarScannerDownloadUrl,omitempty"` 32 VersioningModel string `json:"versioningModel,omitempty" validate:"possible-values=major major-minor semantic full"` 33 Version string `json:"version,omitempty"` 34 CustomScanVersion string `json:"customScanVersion,omitempty"` 35 ProjectKey string `json:"projectKey,omitempty"` 36 CoverageExclusions []string `json:"coverageExclusions,omitempty"` 37 InferJavaBinaries bool `json:"inferJavaBinaries,omitempty"` 38 InferJavaLibraries bool `json:"inferJavaLibraries,omitempty"` 39 Options []string `json:"options,omitempty"` 40 WaitForQualityGate bool `json:"waitForQualityGate,omitempty"` 41 BranchName string `json:"branchName,omitempty"` 42 InferBranchName bool `json:"inferBranchName,omitempty"` 43 ChangeID string `json:"changeId,omitempty"` 44 ChangeBranch string `json:"changeBranch,omitempty"` 45 ChangeTarget string `json:"changeTarget,omitempty"` 46 PullRequestProvider string `json:"pullRequestProvider,omitempty" validate:"possible-values=GitHub"` 47 Owner string `json:"owner,omitempty"` 48 Repository string `json:"repository,omitempty"` 49 GithubToken string `json:"githubToken,omitempty"` 50 DisableInlineComments bool `json:"disableInlineComments,omitempty"` 51 LegacyPRHandling bool `json:"legacyPRHandling,omitempty"` 52 GithubAPIURL string `json:"githubApiUrl,omitempty"` 53 M2Path string `json:"m2Path,omitempty"` 54 } 55 56 type sonarExecuteScanReports struct { 57 } 58 59 func (p *sonarExecuteScanReports) persist(stepConfig sonarExecuteScanOptions, gcpJsonKeyFilePath string, gcsBucketId string, gcsFolderPath string, gcsSubFolder string) { 60 if gcsBucketId == "" { 61 log.Entry().Info("persisting reports to GCS is disabled, because gcsBucketId is empty") 62 return 63 } 64 log.Entry().Info("Uploading reports to Google Cloud Storage...") 65 content := []gcs.ReportOutputParam{ 66 {FilePattern: "**/sonarscan.json", ParamRef: "", StepResultType: "sonarqube"}, 67 {FilePattern: "**/sonarscan-result.json", ParamRef: "", StepResultType: "sonarqube"}, 68 } 69 envVars := []gcs.EnvVar{ 70 {Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: gcpJsonKeyFilePath, Modified: false}, 71 } 72 gcsClient, err := gcs.NewClient(gcs.WithEnvVars(envVars)) 73 if err != nil { 74 log.Entry().Errorf("creation of GCS client failed: %v", err) 75 return 76 } 77 defer gcsClient.Close() 78 structVal := reflect.ValueOf(&stepConfig).Elem() 79 inputParameters := map[string]string{} 80 for i := 0; i < structVal.NumField(); i++ { 81 field := structVal.Type().Field(i) 82 if field.Type.String() == "string" { 83 paramName := strings.Split(field.Tag.Get("json"), ",") 84 paramValue, _ := structVal.Field(i).Interface().(string) 85 inputParameters[paramName[0]] = paramValue 86 } 87 } 88 if err := gcs.PersistReportsToGCS(gcsClient, content, inputParameters, gcsFolderPath, gcsBucketId, gcsSubFolder, doublestar.Glob, os.Stat); err != nil { 89 log.Entry().Errorf("failed to persist reports: %v", err) 90 } 91 } 92 93 type sonarExecuteScanInflux struct { 94 step_data struct { 95 fields struct { 96 sonar bool 97 } 98 tags struct { 99 } 100 } 101 sonarqube_data struct { 102 fields struct { 103 blocker_issues int 104 critical_issues int 105 major_issues int 106 minor_issues int 107 info_issues int 108 } 109 tags struct { 110 } 111 } 112 } 113 114 func (i *sonarExecuteScanInflux) persist(path, resourceName string) { 115 measurementContent := []struct { 116 measurement string 117 valType string 118 name string 119 value interface{} 120 }{ 121 {valType: config.InfluxField, measurement: "step_data", name: "sonar", value: i.step_data.fields.sonar}, 122 {valType: config.InfluxField, measurement: "sonarqube_data", name: "blocker_issues", value: i.sonarqube_data.fields.blocker_issues}, 123 {valType: config.InfluxField, measurement: "sonarqube_data", name: "critical_issues", value: i.sonarqube_data.fields.critical_issues}, 124 {valType: config.InfluxField, measurement: "sonarqube_data", name: "major_issues", value: i.sonarqube_data.fields.major_issues}, 125 {valType: config.InfluxField, measurement: "sonarqube_data", name: "minor_issues", value: i.sonarqube_data.fields.minor_issues}, 126 {valType: config.InfluxField, measurement: "sonarqube_data", name: "info_issues", value: i.sonarqube_data.fields.info_issues}, 127 } 128 129 errCount := 0 130 for _, metric := range measurementContent { 131 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(metric.measurement, fmt.Sprintf("%vs", metric.valType), metric.name), metric.value) 132 if err != nil { 133 log.Entry().WithError(err).Error("Error persisting influx environment.") 134 errCount++ 135 } 136 } 137 if errCount > 0 { 138 log.Entry().Error("failed to persist Influx environment") 139 } 140 } 141 142 // SonarExecuteScanCommand Executes the Sonar scanner 143 func SonarExecuteScanCommand() *cobra.Command { 144 const STEP_NAME = "sonarExecuteScan" 145 146 metadata := sonarExecuteScanMetadata() 147 var stepConfig sonarExecuteScanOptions 148 var startTime time.Time 149 var reports sonarExecuteScanReports 150 var influx sonarExecuteScanInflux 151 var logCollector *log.CollectorHook 152 var splunkClient *splunk.Splunk 153 telemetryClient := &telemetry.Telemetry{} 154 155 var createSonarExecuteScanCmd = &cobra.Command{ 156 Use: STEP_NAME, 157 Short: "Executes the Sonar scanner", 158 Long: `The step executes the [sonar-scanner](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner) cli command to scan the defined sources and publish the results to a SonarQube instance.`, 159 PreRunE: func(cmd *cobra.Command, _ []string) error { 160 startTime = time.Now() 161 log.SetStepName(STEP_NAME) 162 log.SetVerbose(GeneralConfig.Verbose) 163 164 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 165 166 path, _ := os.Getwd() 167 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 168 log.RegisterHook(fatalHook) 169 170 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 171 if err != nil { 172 log.SetErrorCategory(log.ErrorConfiguration) 173 return err 174 } 175 log.RegisterSecret(stepConfig.Token) 176 log.RegisterSecret(stepConfig.GithubToken) 177 178 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 179 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 180 log.RegisterHook(&sentryHook) 181 } 182 183 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 184 splunkClient = &splunk.Splunk{} 185 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 186 log.RegisterHook(logCollector) 187 } 188 189 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 190 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 191 } 192 193 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 194 if err != nil { 195 return err 196 } 197 if err = validation.ValidateStruct(stepConfig); err != nil { 198 log.SetErrorCategory(log.ErrorConfiguration) 199 return err 200 } 201 202 return nil 203 }, 204 Run: func(_ *cobra.Command, _ []string) { 205 stepTelemetryData := telemetry.CustomData{} 206 stepTelemetryData.ErrorCode = "1" 207 handler := func() { 208 reports.persist(stepConfig, GeneralConfig.GCPJsonKeyFilePath, GeneralConfig.GCSBucketId, GeneralConfig.GCSFolderPath, GeneralConfig.GCSSubFolder) 209 influx.persist(GeneralConfig.EnvRootPath, "influx") 210 config.RemoveVaultSecretFiles() 211 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 212 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 213 stepTelemetryData.PiperCommitHash = GitCommit 214 telemetryClient.SetData(&stepTelemetryData) 215 telemetryClient.Send() 216 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 217 splunkClient.Initialize(GeneralConfig.CorrelationID, 218 GeneralConfig.HookConfig.SplunkConfig.Dsn, 219 GeneralConfig.HookConfig.SplunkConfig.Token, 220 GeneralConfig.HookConfig.SplunkConfig.Index, 221 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 222 splunkClient.Send(telemetryClient.GetData(), logCollector) 223 } 224 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 225 splunkClient.Initialize(GeneralConfig.CorrelationID, 226 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 227 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 228 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 229 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 230 splunkClient.Send(telemetryClient.GetData(), logCollector) 231 } 232 } 233 log.DeferExitHandler(handler) 234 defer handler() 235 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 236 sonarExecuteScan(stepConfig, &stepTelemetryData, &influx) 237 stepTelemetryData.ErrorCode = "0" 238 log.Entry().Info("SUCCESS") 239 }, 240 } 241 242 addSonarExecuteScanFlags(createSonarExecuteScanCmd, &stepConfig) 243 return createSonarExecuteScanCmd 244 } 245 246 func addSonarExecuteScanFlags(cmd *cobra.Command, stepConfig *sonarExecuteScanOptions) { 247 cmd.Flags().StringVar(&stepConfig.Instance, "instance", os.Getenv("PIPER_instance"), "Jenkins only: The name of the SonarQube instance defined in the Jenkins settings. DEPRECATED: use serverUrl parameter instead") 248 cmd.Flags().StringVar(&stepConfig.Proxy, "proxy", os.Getenv("PIPER_proxy"), "Proxy URL to be used for communication with the SonarQube instance.") 249 cmd.Flags().StringVar(&stepConfig.ServerURL, "serverUrl", os.Getenv("PIPER_serverUrl"), "The URL to the Sonar backend.") 250 cmd.Flags().StringVar(&stepConfig.Token, "token", os.Getenv("PIPER_token"), "Token used to authenticate with the Sonar Server.") 251 cmd.Flags().StringVar(&stepConfig.Organization, "organization", os.Getenv("PIPER_organization"), "SonarCloud.io only: Organization that the project will be assigned to in SonarCloud.io.") 252 cmd.Flags().StringSliceVar(&stepConfig.CustomTLSCertificateLinks, "customTlsCertificateLinks", []string{}, "List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with custom certificates.") 253 cmd.Flags().StringVar(&stepConfig.SonarScannerDownloadURL, "sonarScannerDownloadUrl", `https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip`, "URL to the sonar-scanner-cli archive.") 254 cmd.Flags().StringVar(&stepConfig.VersioningModel, "versioningModel", `major`, "The versioning model used for the version when reporting the results for the project.") 255 cmd.Flags().StringVar(&stepConfig.Version, "version", os.Getenv("PIPER_version"), "The project version that is reported to SonarQube.") 256 cmd.Flags().StringVar(&stepConfig.CustomScanVersion, "customScanVersion", os.Getenv("PIPER_customScanVersion"), "A custom version used along with the uploaded scan results.") 257 cmd.Flags().StringVar(&stepConfig.ProjectKey, "projectKey", os.Getenv("PIPER_projectKey"), "The project key identifies the project in SonarQube.") 258 cmd.Flags().StringSliceVar(&stepConfig.CoverageExclusions, "coverageExclusions", []string{}, "A list of patterns that should be excluded from the coverage scan.") 259 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.") 260 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.") 261 cmd.Flags().StringSliceVar(&stepConfig.Options, "options", []string{}, "A list of options which are passed to the sonar-scanner.") 262 cmd.Flags().BoolVar(&stepConfig.WaitForQualityGate, "waitForQualityGate", false, "Whether the scan should wait for and consider the result of the quality gate.") 263 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.") 264 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.") 265 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.") 266 cmd.Flags().StringVar(&stepConfig.ChangeBranch, "changeBranch", os.Getenv("PIPER_changeBranch"), "Pull-Request only: The name of the pull-request branch. Automatically inferred from environment variables on supported orchestrators.") 267 cmd.Flags().StringVar(&stepConfig.ChangeTarget, "changeTarget", os.Getenv("PIPER_changeTarget"), "Pull-Request only: The name of the base branch. Automatically inferred from environment variables on supported orchestrators.") 268 cmd.Flags().StringVar(&stepConfig.PullRequestProvider, "pullRequestProvider", `GitHub`, "Pull-Request only: The scm provider.") 269 cmd.Flags().StringVar(&stepConfig.Owner, "owner", os.Getenv("PIPER_owner"), "Pull-Request only: The owner of the scm repository.") 270 cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Pull-Request only: The scm repository.") 271 cmd.Flags().StringVar(&stepConfig.GithubToken, "githubToken", os.Getenv("PIPER_githubToken"), "Pull-Request only: Token for Github to set status on the Pull-Request.") 272 cmd.Flags().BoolVar(&stepConfig.DisableInlineComments, "disableInlineComments", false, "Pull-Request only: Disables the pull-request decoration with inline comments. DEPRECATED: only supported in SonarQube < 7.2") 273 cmd.Flags().BoolVar(&stepConfig.LegacyPRHandling, "legacyPRHandling", false, "Pull-Request only: Activates the pull-request handling using the [GitHub Plugin](https://docs.sonarqube.org/display/PLUG/GitHub+Plugin). DEPRECATED: only supported in SonarQube < 7.2") 274 cmd.Flags().StringVar(&stepConfig.GithubAPIURL, "githubApiUrl", `https://api.github.com`, "Pull-Request only: The URL to the Github API. See [GitHub plugin docs](https://docs.sonarqube.org/display/PLUG/GitHub+Plugin#GitHubPlugin-Usage) DEPRECATED: only supported in SonarQube < 7.2") 275 cmd.Flags().StringVar(&stepConfig.M2Path, "m2Path", os.Getenv("PIPER_m2Path"), "Path to the location of the local repository that should be used.") 276 277 } 278 279 // retrieve step metadata 280 func sonarExecuteScanMetadata() config.StepData { 281 var theMetaData = config.StepData{ 282 Metadata: config.StepMetadata{ 283 Name: "sonarExecuteScan", 284 Aliases: []config.Alias{}, 285 Description: "Executes the Sonar scanner", 286 }, 287 Spec: config.StepSpec{ 288 Inputs: config.StepInputs{ 289 Secrets: []config.StepSecrets{ 290 {Name: "sonarTokenCredentialsId", Description: "Jenkins 'Secret text' credentials ID containing the token used to authenticate with the Sonar Server.", Type: "jenkins"}, 291 {Name: "githubTokenCredentialsId", Description: "Jenkins 'Secret text' credentials ID containing the token used to authenticate with the Github Server.", Type: "jenkins"}, 292 }, 293 Parameters: []config.StepParameters{ 294 { 295 Name: "instance", 296 ResourceRef: []config.ResourceReference{}, 297 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 298 Type: "string", 299 Mandatory: false, 300 Aliases: []config.Alias{}, 301 Default: os.Getenv("PIPER_instance"), 302 }, 303 { 304 Name: "proxy", 305 ResourceRef: []config.ResourceReference{}, 306 Scope: []string{"PARAMETERS", "STEPS", "STAGES"}, 307 Type: "string", 308 Mandatory: false, 309 Aliases: []config.Alias{}, 310 Default: os.Getenv("PIPER_proxy"), 311 }, 312 { 313 Name: "serverUrl", 314 ResourceRef: []config.ResourceReference{}, 315 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 316 Type: "string", 317 Mandatory: false, 318 Aliases: []config.Alias{{Name: "host"}, {Name: "sonarServerUrl"}}, 319 Default: os.Getenv("PIPER_serverUrl"), 320 }, 321 { 322 Name: "token", 323 ResourceRef: []config.ResourceReference{ 324 { 325 Name: "sonarVaultSecretName", 326 Type: "vaultSecret", 327 Default: "sonar", 328 }, 329 330 { 331 Name: "sonarTokenCredentialsId", 332 Type: "secret", 333 }, 334 }, 335 Scope: []string{"PARAMETERS"}, 336 Type: "string", 337 Mandatory: false, 338 Aliases: []config.Alias{{Name: "sonarToken"}}, 339 Default: os.Getenv("PIPER_token"), 340 }, 341 { 342 Name: "organization", 343 ResourceRef: []config.ResourceReference{}, 344 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 345 Type: "string", 346 Mandatory: false, 347 Aliases: []config.Alias{}, 348 Default: os.Getenv("PIPER_organization"), 349 }, 350 { 351 Name: "customTlsCertificateLinks", 352 ResourceRef: []config.ResourceReference{}, 353 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 354 Type: "[]string", 355 Mandatory: false, 356 Aliases: []config.Alias{}, 357 Default: []string{}, 358 }, 359 { 360 Name: "sonarScannerDownloadUrl", 361 ResourceRef: []config.ResourceReference{}, 362 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 363 Type: "string", 364 Mandatory: false, 365 Aliases: []config.Alias{}, 366 Default: `https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip`, 367 }, 368 { 369 Name: "versioningModel", 370 ResourceRef: []config.ResourceReference{}, 371 Scope: []string{"GENERAL", "STAGES", "STEPS", "PARAMETERS"}, 372 Type: "string", 373 Mandatory: false, 374 Aliases: []config.Alias{}, 375 Default: `major`, 376 }, 377 { 378 Name: "version", 379 ResourceRef: []config.ResourceReference{ 380 { 381 Name: "commonPipelineEnvironment", 382 Param: "artifactVersion", 383 }, 384 }, 385 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 386 Type: "string", 387 Mandatory: false, 388 Aliases: []config.Alias{{Name: "projectVersion", Deprecated: true}}, 389 Default: os.Getenv("PIPER_version"), 390 }, 391 { 392 Name: "customScanVersion", 393 ResourceRef: []config.ResourceReference{}, 394 Scope: []string{"GENERAL", "STAGES", "STEPS", "PARAMETERS"}, 395 Type: "string", 396 Mandatory: false, 397 Aliases: []config.Alias{}, 398 Default: os.Getenv("PIPER_customScanVersion"), 399 }, 400 { 401 Name: "projectKey", 402 ResourceRef: []config.ResourceReference{}, 403 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 404 Type: "string", 405 Mandatory: false, 406 Aliases: []config.Alias{}, 407 Default: os.Getenv("PIPER_projectKey"), 408 }, 409 { 410 Name: "coverageExclusions", 411 ResourceRef: []config.ResourceReference{}, 412 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 413 Type: "[]string", 414 Mandatory: false, 415 Aliases: []config.Alias{}, 416 Default: []string{}, 417 }, 418 { 419 Name: "inferJavaBinaries", 420 ResourceRef: []config.ResourceReference{}, 421 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 422 Type: "bool", 423 Mandatory: false, 424 Aliases: []config.Alias{}, 425 Default: false, 426 }, 427 { 428 Name: "inferJavaLibraries", 429 ResourceRef: []config.ResourceReference{}, 430 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 431 Type: "bool", 432 Mandatory: false, 433 Aliases: []config.Alias{}, 434 Default: false, 435 }, 436 { 437 Name: "options", 438 ResourceRef: []config.ResourceReference{}, 439 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 440 Type: "[]string", 441 Mandatory: false, 442 Aliases: []config.Alias{{Name: "sonarProperties", Deprecated: true}}, 443 Default: []string{}, 444 }, 445 { 446 Name: "waitForQualityGate", 447 ResourceRef: []config.ResourceReference{}, 448 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 449 Type: "bool", 450 Mandatory: false, 451 Aliases: []config.Alias{}, 452 Default: false, 453 }, 454 { 455 Name: "branchName", 456 ResourceRef: []config.ResourceReference{}, 457 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 458 Type: "string", 459 Mandatory: false, 460 Aliases: []config.Alias{}, 461 Default: os.Getenv("PIPER_branchName"), 462 }, 463 { 464 Name: "inferBranchName", 465 ResourceRef: []config.ResourceReference{}, 466 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 467 Type: "bool", 468 Mandatory: false, 469 Aliases: []config.Alias{}, 470 Default: false, 471 }, 472 { 473 Name: "changeId", 474 ResourceRef: []config.ResourceReference{}, 475 Scope: []string{"PARAMETERS"}, 476 Type: "string", 477 Mandatory: false, 478 Aliases: []config.Alias{}, 479 Default: os.Getenv("PIPER_changeId"), 480 }, 481 { 482 Name: "changeBranch", 483 ResourceRef: []config.ResourceReference{}, 484 Scope: []string{"PARAMETERS"}, 485 Type: "string", 486 Mandatory: false, 487 Aliases: []config.Alias{}, 488 Default: os.Getenv("PIPER_changeBranch"), 489 }, 490 { 491 Name: "changeTarget", 492 ResourceRef: []config.ResourceReference{}, 493 Scope: []string{"PARAMETERS"}, 494 Type: "string", 495 Mandatory: false, 496 Aliases: []config.Alias{}, 497 Default: os.Getenv("PIPER_changeTarget"), 498 }, 499 { 500 Name: "pullRequestProvider", 501 ResourceRef: []config.ResourceReference{}, 502 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 503 Type: "string", 504 Mandatory: false, 505 Aliases: []config.Alias{}, 506 Default: `GitHub`, 507 }, 508 { 509 Name: "owner", 510 ResourceRef: []config.ResourceReference{ 511 { 512 Name: "commonPipelineEnvironment", 513 Param: "github/owner", 514 }, 515 }, 516 Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, 517 Type: "string", 518 Mandatory: false, 519 Aliases: []config.Alias{{Name: "githubOrg"}}, 520 Default: os.Getenv("PIPER_owner"), 521 }, 522 { 523 Name: "repository", 524 ResourceRef: []config.ResourceReference{ 525 { 526 Name: "commonPipelineEnvironment", 527 Param: "github/repository", 528 }, 529 }, 530 Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, 531 Type: "string", 532 Mandatory: false, 533 Aliases: []config.Alias{{Name: "githubRepo"}}, 534 Default: os.Getenv("PIPER_repository"), 535 }, 536 { 537 Name: "githubToken", 538 ResourceRef: []config.ResourceReference{ 539 { 540 Name: "githubTokenCredentialsId", 541 Type: "secret", 542 }, 543 544 { 545 Name: "githubVaultSecretName", 546 Type: "vaultSecret", 547 Default: "github", 548 }, 549 }, 550 Scope: []string{"PARAMETERS"}, 551 Type: "string", 552 Mandatory: false, 553 Aliases: []config.Alias{{Name: "access_token"}}, 554 Default: os.Getenv("PIPER_githubToken"), 555 }, 556 { 557 Name: "disableInlineComments", 558 ResourceRef: []config.ResourceReference{}, 559 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 560 Type: "bool", 561 Mandatory: false, 562 Aliases: []config.Alias{}, 563 Default: false, 564 }, 565 { 566 Name: "legacyPRHandling", 567 ResourceRef: []config.ResourceReference{}, 568 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 569 Type: "bool", 570 Mandatory: false, 571 Aliases: []config.Alias{}, 572 Default: false, 573 }, 574 { 575 Name: "githubApiUrl", 576 ResourceRef: []config.ResourceReference{}, 577 Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, 578 Type: "string", 579 Mandatory: false, 580 Aliases: []config.Alias{}, 581 Default: `https://api.github.com`, 582 }, 583 { 584 Name: "m2Path", 585 ResourceRef: []config.ResourceReference{}, 586 Scope: []string{"GENERAL", "STEPS", "STAGES", "PARAMETERS"}, 587 Type: "string", 588 Mandatory: false, 589 Aliases: []config.Alias{{Name: "maven/m2Path"}}, 590 Default: os.Getenv("PIPER_m2Path"), 591 }, 592 }, 593 }, 594 Containers: []config.Container{ 595 {Name: "sonar", Image: "sonarsource/sonar-scanner-cli:4.8", Options: []config.Option{{Name: "-u", Value: "0"}}}, 596 }, 597 Outputs: config.StepOutputs{ 598 Resources: []config.StepResources{ 599 { 600 Name: "reports", 601 Type: "reports", 602 Parameters: []map[string]interface{}{ 603 {"filePattern": "**/sonarscan.json", "type": "sonarqube"}, 604 {"filePattern": "**/sonarscan-result.json", "type": "sonarqube"}, 605 }, 606 }, 607 { 608 Name: "influx", 609 Type: "influx", 610 Parameters: []map[string]interface{}{ 611 {"name": "step_data", "fields": []map[string]string{{"name": "sonar"}}}, 612 {"name": "sonarqube_data", "fields": []map[string]string{{"name": "blocker_issues"}, {"name": "critical_issues"}, {"name": "major_issues"}, {"name": "minor_issues"}, {"name": "info_issues"}}}, 613 }, 614 }, 615 }, 616 }, 617 }, 618 } 619 return theMetaData 620 }