github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/gctsExecuteABAPQualityChecks_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 "time" 9 10 "github.com/SAP/jenkins-library/pkg/config" 11 "github.com/SAP/jenkins-library/pkg/log" 12 "github.com/SAP/jenkins-library/pkg/splunk" 13 "github.com/SAP/jenkins-library/pkg/telemetry" 14 "github.com/SAP/jenkins-library/pkg/validation" 15 "github.com/spf13/cobra" 16 ) 17 18 type gctsExecuteABAPQualityChecksOptions struct { 19 Username string `json:"username,omitempty"` 20 Password string `json:"password,omitempty"` 21 Host string `json:"host,omitempty"` 22 Repository string `json:"repository,omitempty"` 23 Client string `json:"client,omitempty"` 24 AUnitTest bool `json:"aUnitTest,omitempty"` 25 AtcCheck bool `json:"atcCheck,omitempty"` 26 AtcVariant string `json:"atcVariant,omitempty"` 27 Scope string `json:"scope,omitempty"` 28 Commit string `json:"commit,omitempty"` 29 Workspace string `json:"workspace,omitempty"` 30 AtcResultsFileName string `json:"atcResultsFileName,omitempty"` 31 AUnitResultsFileName string `json:"aUnitResultsFileName,omitempty"` 32 QueryParameters map[string]interface{} `json:"queryParameters,omitempty"` 33 SkipSSLVerification bool `json:"skipSSLVerification,omitempty"` 34 } 35 36 // GctsExecuteABAPQualityChecksCommand Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope. 37 func GctsExecuteABAPQualityChecksCommand() *cobra.Command { 38 const STEP_NAME = "gctsExecuteABAPQualityChecks" 39 40 metadata := gctsExecuteABAPQualityChecksMetadata() 41 var stepConfig gctsExecuteABAPQualityChecksOptions 42 var startTime time.Time 43 var logCollector *log.CollectorHook 44 var splunkClient *splunk.Splunk 45 telemetryClient := &telemetry.Telemetry{} 46 47 var createGctsExecuteABAPQualityChecksCmd = &cobra.Command{ 48 Use: STEP_NAME, 49 Short: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", 50 Long: `This step executes ABAP unit test and ATC checks for a specified scope of objects that exist in a local Git repository on an ABAP system. 51 Depending on your use case, you can specify a scope of objects for which you want to execute the checks. In addition, you can choose whether you want to execute only ABAP units tests, or only ATC checks, or both. 52 By default, both checks are executed. 53 <br/> 54 The results of the checks are stored in a [Checkstyle](https://checkstyle.sourceforge.io/) format. With the help of the Jenkins [Warnings-Next-Generation](https://plugins.jenkins.io/warnings-ng/) Plugin), you can view the issues found, and navigate to the exact line of the source code where the issue occurred. 55 To make the findings visible in the Jenkins plug-in, you need to use the ` + "`" + `recordIssues` + "`" + ` step, as displayed in the ` + "`" + `Example` + "`" + ` section below. 56 <br/> 57 You can use this step as of SAP S/4HANA 2020 with SAP Note [3159798](https://launchpad.support.sap.com/#/notes/3159798) implemented.`, 58 PreRunE: func(cmd *cobra.Command, _ []string) error { 59 startTime = time.Now() 60 log.SetStepName(STEP_NAME) 61 log.SetVerbose(GeneralConfig.Verbose) 62 63 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 64 65 path, _ := os.Getwd() 66 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 67 log.RegisterHook(fatalHook) 68 69 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 70 if err != nil { 71 log.SetErrorCategory(log.ErrorConfiguration) 72 return err 73 } 74 log.RegisterSecret(stepConfig.Username) 75 log.RegisterSecret(stepConfig.Password) 76 77 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 78 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 79 log.RegisterHook(&sentryHook) 80 } 81 82 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 83 splunkClient = &splunk.Splunk{} 84 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 85 log.RegisterHook(logCollector) 86 } 87 88 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 89 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 90 } 91 92 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 93 if err != nil { 94 return err 95 } 96 if err = validation.ValidateStruct(stepConfig); err != nil { 97 log.SetErrorCategory(log.ErrorConfiguration) 98 return err 99 } 100 101 return nil 102 }, 103 Run: func(_ *cobra.Command, _ []string) { 104 stepTelemetryData := telemetry.CustomData{} 105 stepTelemetryData.ErrorCode = "1" 106 handler := func() { 107 config.RemoveVaultSecretFiles() 108 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 109 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 110 stepTelemetryData.PiperCommitHash = GitCommit 111 telemetryClient.SetData(&stepTelemetryData) 112 telemetryClient.Send() 113 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 114 splunkClient.Initialize(GeneralConfig.CorrelationID, 115 GeneralConfig.HookConfig.SplunkConfig.Dsn, 116 GeneralConfig.HookConfig.SplunkConfig.Token, 117 GeneralConfig.HookConfig.SplunkConfig.Index, 118 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 119 splunkClient.Send(telemetryClient.GetData(), logCollector) 120 } 121 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 122 splunkClient.Initialize(GeneralConfig.CorrelationID, 123 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 124 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 125 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 126 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 127 splunkClient.Send(telemetryClient.GetData(), logCollector) 128 } 129 } 130 log.DeferExitHandler(handler) 131 defer handler() 132 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 133 gctsExecuteABAPQualityChecks(stepConfig, &stepTelemetryData) 134 stepTelemetryData.ErrorCode = "0" 135 log.Entry().Info("SUCCESS") 136 }, 137 } 138 139 addGctsExecuteABAPQualityChecksFlags(createGctsExecuteABAPQualityChecksCmd, &stepConfig) 140 return createGctsExecuteABAPQualityChecksCmd 141 } 142 143 func addGctsExecuteABAPQualityChecksFlags(cmd *cobra.Command, stepConfig *gctsExecuteABAPQualityChecksOptions) { 144 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User that authenticates to the ABAP system. **Note** - Don´t provide this parameter directly. Either set it in the environment, or in the Jenkins credentials store, and provide the ID as value of the `abapCredentialsId` parameter.") 145 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password of the ABAP user that authenticates to the ABAP system. **Note** - Don´t provide this parameter directly. Either set it in the environment, or in the Jenkins credentials store, and provide the ID as value of the `abapCredentialsId` parameter.") 146 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Protocol and host of the ABAP system, including the port. Please provide it in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.") 147 cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Name (ID) of the local repository on the ABAP system") 148 cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "Client of the ABAP system in which you want to execute the checks") 149 cmd.Flags().BoolVar(&stepConfig.AUnitTest, "aUnitTest", true, "Indication whether you want to execute the ABAP Unit tests. If the ABAP Unit tests fail, the results are mapped as follows to the statuses available in the Jenkins plugin. (Successful ABAP unit test results are not displayed.)\n<br/>\n- Failed with severity `fatal` is displayed as an `Error`.\n<br/>\n- Failed with severity `critical` is displayed as an `Error`.\n<br/>\n- Failed with severity `warning` is displayed as a `Warning`.\n") 150 cmd.Flags().BoolVar(&stepConfig.AtcCheck, "atcCheck", true, "Indication whether you want to execute the ATC checks. If the ATC checks result in errors with priorities 1 and 2, they are considered as failed. The results are mapped as follows to the statuses available in the Jenkins plugin. (Successful ATC check results are not displayed.)\n<br/>\n- Priorities 1 and 2 are displayed as an `Error`.\n<br/>\n- Priority 3 is displayed as a `Warning`.\n") 151 cmd.Flags().StringVar(&stepConfig.AtcVariant, "atcVariant", `DEFAULT`, "Variant for ATC checks") 152 cmd.Flags().StringVar(&stepConfig.Scope, "scope", `repository`, "Scope of objects for which you want to execute the checks:\n<br/>\n- `localChangedObjects`: The object scope is derived from the last activity in the local repository. The checks are executed for the individual objects.\n<br/>\n- `remoteChangedObjects`: The object scope is the delta between the commit that triggered the pipeline and the current commit in the remote repository. The checks are executed for the individual objects.\n<br/>\n- `localChangedPackages`: The object scope is derived from the last activity in the local repository. All objects are resolved into packages. The checks are executed for the packages.\n<br/>\n- `remoteChangedPackages`: The object scope is the delta between the commit that triggered the pipeline and the current commit in the remote repository. All objects are resolved into packages. The checks are executed for the packages.\n<br/>\n- `repository`: The object scope comprises all objects that are part of the local repository. The checks are executed for the individual objects. Packages (DEVC) are excluded. This is the default scope.\n<br/>\n- `packages`: The object scope comprises all packages that are part of the local repository. The checks are executed for the packages.\n") 153 cmd.Flags().StringVar(&stepConfig.Commit, "commit", os.Getenv("PIPER_commit"), "ID of the commit that triggered the pipeline or any other commit used to calculate the object scope. Specifying a commit is mandatory for the `remoteChangedObjects` and `remoteChangedPackages` scopes.") 154 cmd.Flags().StringVar(&stepConfig.Workspace, "workspace", os.Getenv("PIPER_workspace"), "Absolute path to the directory that contains the source code that your CI/CD tool checks out. For example, in Jenkins, the workspace parameter is `/var/jenkins_home/workspace/<jobName>/`. As an alternative, you can use Jenkins's predefined environmental variable `WORKSPACE`.") 155 cmd.Flags().StringVar(&stepConfig.AtcResultsFileName, "atcResultsFileName", `ATCResults.xml`, "Specifies an output file name for the results of the ATC checks.") 156 cmd.Flags().StringVar(&stepConfig.AUnitResultsFileName, "aUnitResultsFileName", `AUnitResults.xml`, "Specifies an output file name for the results of the ABAP Unit tests.") 157 158 cmd.Flags().BoolVar(&stepConfig.SkipSSLVerification, "skipSSLVerification", false, "Skip the verification of SSL (Secure Socket Layer) certificates when using HTTPS. This parameter is **not recommended** for productive environments.") 159 160 cmd.MarkFlagRequired("username") 161 cmd.MarkFlagRequired("password") 162 cmd.MarkFlagRequired("host") 163 cmd.MarkFlagRequired("repository") 164 cmd.MarkFlagRequired("client") 165 cmd.MarkFlagRequired("workspace") 166 } 167 168 // retrieve step metadata 169 func gctsExecuteABAPQualityChecksMetadata() config.StepData { 170 var theMetaData = config.StepData{ 171 Metadata: config.StepMetadata{ 172 Name: "gctsExecuteABAPQualityChecks", 173 Aliases: []config.Alias{}, 174 Description: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", 175 }, 176 Spec: config.StepSpec{ 177 Inputs: config.StepInputs{ 178 Secrets: []config.StepSecrets{ 179 {Name: "abapCredentialsId", Description: "ID taken from the Jenkins credentials store containing user name and password of the user that authenticates to the ABAP system on which you want to execute the checks.", Type: "jenkins"}, 180 }, 181 Parameters: []config.StepParameters{ 182 { 183 Name: "username", 184 ResourceRef: []config.ResourceReference{ 185 { 186 Name: "abapCredentialsId", 187 Param: "username", 188 Type: "secret", 189 }, 190 }, 191 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 192 Type: "string", 193 Mandatory: true, 194 Aliases: []config.Alias{}, 195 Default: os.Getenv("PIPER_username"), 196 }, 197 { 198 Name: "password", 199 ResourceRef: []config.ResourceReference{ 200 { 201 Name: "abapCredentialsId", 202 Param: "password", 203 Type: "secret", 204 }, 205 }, 206 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 207 Type: "string", 208 Mandatory: true, 209 Aliases: []config.Alias{}, 210 Default: os.Getenv("PIPER_password"), 211 }, 212 { 213 Name: "host", 214 ResourceRef: []config.ResourceReference{}, 215 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 216 Type: "string", 217 Mandatory: true, 218 Aliases: []config.Alias{}, 219 Default: os.Getenv("PIPER_host"), 220 }, 221 { 222 Name: "repository", 223 ResourceRef: []config.ResourceReference{}, 224 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 225 Type: "string", 226 Mandatory: true, 227 Aliases: []config.Alias{}, 228 Default: os.Getenv("PIPER_repository"), 229 }, 230 { 231 Name: "client", 232 ResourceRef: []config.ResourceReference{}, 233 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 234 Type: "string", 235 Mandatory: true, 236 Aliases: []config.Alias{}, 237 Default: os.Getenv("PIPER_client"), 238 }, 239 { 240 Name: "aUnitTest", 241 ResourceRef: []config.ResourceReference{}, 242 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 243 Type: "bool", 244 Mandatory: false, 245 Aliases: []config.Alias{}, 246 Default: true, 247 }, 248 { 249 Name: "atcCheck", 250 ResourceRef: []config.ResourceReference{}, 251 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 252 Type: "bool", 253 Mandatory: false, 254 Aliases: []config.Alias{}, 255 Default: true, 256 }, 257 { 258 Name: "atcVariant", 259 ResourceRef: []config.ResourceReference{}, 260 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 261 Type: "string", 262 Mandatory: false, 263 Aliases: []config.Alias{}, 264 Default: `DEFAULT`, 265 }, 266 { 267 Name: "scope", 268 ResourceRef: []config.ResourceReference{}, 269 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 270 Type: "string", 271 Mandatory: false, 272 Aliases: []config.Alias{}, 273 Default: `repository`, 274 }, 275 { 276 Name: "commit", 277 ResourceRef: []config.ResourceReference{}, 278 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 279 Type: "string", 280 Mandatory: false, 281 Aliases: []config.Alias{}, 282 Default: os.Getenv("PIPER_commit"), 283 }, 284 { 285 Name: "workspace", 286 ResourceRef: []config.ResourceReference{}, 287 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 288 Type: "string", 289 Mandatory: true, 290 Aliases: []config.Alias{}, 291 Default: os.Getenv("PIPER_workspace"), 292 }, 293 { 294 Name: "atcResultsFileName", 295 ResourceRef: []config.ResourceReference{}, 296 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 297 Type: "string", 298 Mandatory: false, 299 Aliases: []config.Alias{}, 300 Default: `ATCResults.xml`, 301 }, 302 { 303 Name: "aUnitResultsFileName", 304 ResourceRef: []config.ResourceReference{}, 305 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 306 Type: "string", 307 Mandatory: false, 308 Aliases: []config.Alias{}, 309 Default: `AUnitResults.xml`, 310 }, 311 { 312 Name: "queryParameters", 313 ResourceRef: []config.ResourceReference{}, 314 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 315 Type: "map[string]interface{}", 316 Mandatory: false, 317 Aliases: []config.Alias{}, 318 }, 319 { 320 Name: "skipSSLVerification", 321 ResourceRef: []config.ResourceReference{}, 322 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 323 Type: "bool", 324 Mandatory: false, 325 Aliases: []config.Alias{}, 326 Default: false, 327 }, 328 }, 329 }, 330 }, 331 } 332 return theMetaData 333 }