github.com/jaylevin/jenkins-library@v1.230.4/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 } 33 34 // GctsExecuteABAPQualityChecksCommand Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope. 35 func GctsExecuteABAPQualityChecksCommand() *cobra.Command { 36 const STEP_NAME = "gctsExecuteABAPQualityChecks" 37 38 metadata := gctsExecuteABAPQualityChecksMetadata() 39 var stepConfig gctsExecuteABAPQualityChecksOptions 40 var startTime time.Time 41 var logCollector *log.CollectorHook 42 var splunkClient *splunk.Splunk 43 telemetryClient := &telemetry.Telemetry{} 44 45 var createGctsExecuteABAPQualityChecksCmd = &cobra.Command{ 46 Use: STEP_NAME, 47 Short: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", 48 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. 49 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. 50 By default, both checks are executed. 51 <br/> 52 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. 53 To make the findings visible in the Jenkins plug-in, you need to use the ` + "`" + `recordIssues` + "`" + ` step, as displayed in the ` + "`" + `Example` + "`" + ` section below. 54 <br/> 55 You can use this step as of SAP S/4HANA 2020 with SAP Note [3159798](https://launchpad.support.sap.com/#/notes/3159798) implemented.`, 56 PreRunE: func(cmd *cobra.Command, _ []string) error { 57 startTime = time.Now() 58 log.SetStepName(STEP_NAME) 59 log.SetVerbose(GeneralConfig.Verbose) 60 61 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 62 63 path, _ := os.Getwd() 64 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 65 log.RegisterHook(fatalHook) 66 67 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 68 if err != nil { 69 log.SetErrorCategory(log.ErrorConfiguration) 70 return err 71 } 72 log.RegisterSecret(stepConfig.Username) 73 log.RegisterSecret(stepConfig.Password) 74 75 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 76 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 77 log.RegisterHook(&sentryHook) 78 } 79 80 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 81 splunkClient = &splunk.Splunk{} 82 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 83 log.RegisterHook(logCollector) 84 } 85 86 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 87 if err != nil { 88 return err 89 } 90 if err = validation.ValidateStruct(stepConfig); err != nil { 91 log.SetErrorCategory(log.ErrorConfiguration) 92 return err 93 } 94 95 return nil 96 }, 97 Run: func(_ *cobra.Command, _ []string) { 98 stepTelemetryData := telemetry.CustomData{} 99 stepTelemetryData.ErrorCode = "1" 100 handler := func() { 101 config.RemoveVaultSecretFiles() 102 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 103 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 104 stepTelemetryData.PiperCommitHash = GitCommit 105 telemetryClient.SetData(&stepTelemetryData) 106 telemetryClient.Send() 107 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 108 splunkClient.Send(telemetryClient.GetData(), logCollector) 109 } 110 } 111 log.DeferExitHandler(handler) 112 defer handler() 113 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 114 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 115 splunkClient.Initialize(GeneralConfig.CorrelationID, 116 GeneralConfig.HookConfig.SplunkConfig.Dsn, 117 GeneralConfig.HookConfig.SplunkConfig.Token, 118 GeneralConfig.HookConfig.SplunkConfig.Index, 119 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 120 } 121 gctsExecuteABAPQualityChecks(stepConfig, &stepTelemetryData) 122 stepTelemetryData.ErrorCode = "0" 123 log.Entry().Info("SUCCESS") 124 }, 125 } 126 127 addGctsExecuteABAPQualityChecksFlags(createGctsExecuteABAPQualityChecksCmd, &stepConfig) 128 return createGctsExecuteABAPQualityChecksCmd 129 } 130 131 func addGctsExecuteABAPQualityChecksFlags(cmd *cobra.Command, stepConfig *gctsExecuteABAPQualityChecksOptions) { 132 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.") 133 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.") 134 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`.") 135 cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Name (ID) of the local repository on the ABAP system") 136 cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "Client of the ABAP system in which you want to execute the checks") 137 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") 138 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") 139 cmd.Flags().StringVar(&stepConfig.AtcVariant, "atcVariant", `DEFAULT`, "Variant for ATC checks") 140 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") 141 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.") 142 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`.") 143 cmd.Flags().StringVar(&stepConfig.AtcResultsFileName, "atcResultsFileName", `ATCResults.xml`, "Specifies an output file name for the results of the ATC checks.") 144 cmd.Flags().StringVar(&stepConfig.AUnitResultsFileName, "aUnitResultsFileName", `AUnitResults.xml`, "Specifies an output file name for the results of the ABAP Unit tests.") 145 146 cmd.MarkFlagRequired("username") 147 cmd.MarkFlagRequired("password") 148 cmd.MarkFlagRequired("host") 149 cmd.MarkFlagRequired("repository") 150 cmd.MarkFlagRequired("client") 151 cmd.MarkFlagRequired("workspace") 152 } 153 154 // retrieve step metadata 155 func gctsExecuteABAPQualityChecksMetadata() config.StepData { 156 var theMetaData = config.StepData{ 157 Metadata: config.StepMetadata{ 158 Name: "gctsExecuteABAPQualityChecks", 159 Aliases: []config.Alias{}, 160 Description: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", 161 }, 162 Spec: config.StepSpec{ 163 Inputs: config.StepInputs{ 164 Secrets: []config.StepSecrets{ 165 {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"}, 166 }, 167 Parameters: []config.StepParameters{ 168 { 169 Name: "username", 170 ResourceRef: []config.ResourceReference{ 171 { 172 Name: "abapCredentialsId", 173 Param: "username", 174 Type: "secret", 175 }, 176 }, 177 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 178 Type: "string", 179 Mandatory: true, 180 Aliases: []config.Alias{}, 181 Default: os.Getenv("PIPER_username"), 182 }, 183 { 184 Name: "password", 185 ResourceRef: []config.ResourceReference{ 186 { 187 Name: "abapCredentialsId", 188 Param: "password", 189 Type: "secret", 190 }, 191 }, 192 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 193 Type: "string", 194 Mandatory: true, 195 Aliases: []config.Alias{}, 196 Default: os.Getenv("PIPER_password"), 197 }, 198 { 199 Name: "host", 200 ResourceRef: []config.ResourceReference{}, 201 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 202 Type: "string", 203 Mandatory: true, 204 Aliases: []config.Alias{}, 205 Default: os.Getenv("PIPER_host"), 206 }, 207 { 208 Name: "repository", 209 ResourceRef: []config.ResourceReference{}, 210 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 211 Type: "string", 212 Mandatory: true, 213 Aliases: []config.Alias{}, 214 Default: os.Getenv("PIPER_repository"), 215 }, 216 { 217 Name: "client", 218 ResourceRef: []config.ResourceReference{}, 219 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 220 Type: "string", 221 Mandatory: true, 222 Aliases: []config.Alias{}, 223 Default: os.Getenv("PIPER_client"), 224 }, 225 { 226 Name: "aUnitTest", 227 ResourceRef: []config.ResourceReference{}, 228 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 229 Type: "bool", 230 Mandatory: false, 231 Aliases: []config.Alias{}, 232 Default: true, 233 }, 234 { 235 Name: "atcCheck", 236 ResourceRef: []config.ResourceReference{}, 237 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 238 Type: "bool", 239 Mandatory: false, 240 Aliases: []config.Alias{}, 241 Default: true, 242 }, 243 { 244 Name: "atcVariant", 245 ResourceRef: []config.ResourceReference{}, 246 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 247 Type: "string", 248 Mandatory: false, 249 Aliases: []config.Alias{}, 250 Default: `DEFAULT`, 251 }, 252 { 253 Name: "scope", 254 ResourceRef: []config.ResourceReference{}, 255 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 256 Type: "string", 257 Mandatory: false, 258 Aliases: []config.Alias{}, 259 Default: `repository`, 260 }, 261 { 262 Name: "commit", 263 ResourceRef: []config.ResourceReference{}, 264 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 265 Type: "string", 266 Mandatory: false, 267 Aliases: []config.Alias{}, 268 Default: os.Getenv("PIPER_commit"), 269 }, 270 { 271 Name: "workspace", 272 ResourceRef: []config.ResourceReference{}, 273 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 274 Type: "string", 275 Mandatory: true, 276 Aliases: []config.Alias{}, 277 Default: os.Getenv("PIPER_workspace"), 278 }, 279 { 280 Name: "atcResultsFileName", 281 ResourceRef: []config.ResourceReference{}, 282 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 283 Type: "string", 284 Mandatory: false, 285 Aliases: []config.Alias{}, 286 Default: `ATCResults.xml`, 287 }, 288 { 289 Name: "aUnitResultsFileName", 290 ResourceRef: []config.ResourceReference{}, 291 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 292 Type: "string", 293 Mandatory: false, 294 Aliases: []config.Alias{}, 295 Default: `AUnitResults.xml`, 296 }, 297 }, 298 }, 299 }, 300 } 301 return theMetaData 302 }