github.com/xgoffin/jenkins-library@v1.154.0/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 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. 52 To make the findings visible in Jenkins interface, you will need to use step recordIssues. An example will be shown in the Example section. 53 <br /> 54 You can use this step as of SAP S/4HANA 2020.`, 55 PreRunE: func(cmd *cobra.Command, _ []string) error { 56 startTime = time.Now() 57 log.SetStepName(STEP_NAME) 58 log.SetVerbose(GeneralConfig.Verbose) 59 60 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 61 62 path, _ := os.Getwd() 63 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 64 log.RegisterHook(fatalHook) 65 66 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 67 if err != nil { 68 log.SetErrorCategory(log.ErrorConfiguration) 69 return err 70 } 71 log.RegisterSecret(stepConfig.Username) 72 log.RegisterSecret(stepConfig.Password) 73 74 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 75 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 76 log.RegisterHook(&sentryHook) 77 } 78 79 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 80 splunkClient = &splunk.Splunk{} 81 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 82 log.RegisterHook(logCollector) 83 } 84 85 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 86 if err != nil { 87 return err 88 } 89 if err = validation.ValidateStruct(stepConfig); err != nil { 90 log.SetErrorCategory(log.ErrorConfiguration) 91 return err 92 } 93 94 return nil 95 }, 96 Run: func(_ *cobra.Command, _ []string) { 97 stepTelemetryData := telemetry.CustomData{} 98 stepTelemetryData.ErrorCode = "1" 99 handler := func() { 100 config.RemoveVaultSecretFiles() 101 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 102 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 103 stepTelemetryData.PiperCommitHash = GitCommit 104 telemetryClient.SetData(&stepTelemetryData) 105 telemetryClient.Send() 106 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 107 splunkClient.Send(telemetryClient.GetData(), logCollector) 108 } 109 } 110 log.DeferExitHandler(handler) 111 defer handler() 112 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 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 } 120 gctsExecuteABAPQualityChecks(stepConfig, &stepTelemetryData) 121 stepTelemetryData.ErrorCode = "0" 122 log.Entry().Info("SUCCESS") 123 }, 124 } 125 126 addGctsExecuteABAPQualityChecksFlags(createGctsExecuteABAPQualityChecksCmd, &stepConfig) 127 return createGctsExecuteABAPQualityChecksCmd 128 } 129 130 func addGctsExecuteABAPQualityChecksFlags(cmd *cobra.Command, stepConfig *gctsExecuteABAPQualityChecksOptions) { 131 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.") 132 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.") 133 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Protocol and host of the ABAP system, including the port. Please provide in the format <protocol>://<host>:<port>. Supported protocols are http and https.") 134 cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Name (ID) of the local repository on the ABAP system") 135 cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "Client of the ABAP system in which you want to execute the checks") 136 cmd.Flags().BoolVar(&stepConfig.AUnitTest, "aUnitTest", true, "Indication whether you want to execute the unit test checks.") 137 cmd.Flags().BoolVar(&stepConfig.AtcCheck, "atcCheck", true, "Indication whether you want to execute the ATC checks.") 138 cmd.Flags().StringVar(&stepConfig.AtcVariant, "atcVariant", `DEFAULT_REMOTE_REF`, "Variant for ATC checks") 139 cmd.Flags().StringVar(&stepConfig.Scope, "scope", `repository`, "Scope of objects for which you want to execute the checks:\n\n * localChangedObjects - object delta derived from last activity in the local repository. The checks are executed for the individual objects.\n * remoteChangedObjects - object 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 * localChangedPackages - object delta derived from last activity in the local repository. All objects are resolved into packages. The checks are executed for the packages.\n * remoteChangedPackages - object 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 * repository - 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 * packages - all packages that are part of the local repository . The checks are executed for the packages.\n") 140 cmd.Flags().StringVar(&stepConfig.Commit, "commit", os.Getenv("PIPER_commit"), "ID of the commit that triggered the pipeline or any other commit to compare objects. For scopes remoteChangedObjects and remoteChangedPackages secifying a commit it's mandatory.") 141 cmd.Flags().StringVar(&stepConfig.Workspace, "workspace", os.Getenv("PIPER_workspace"), "Absolute path to directory which contains the source code that your CI/CD tool checks out. For example in Jenkins, the workspace parameter is /var/jenkins_home/workspace/<jobName>/") 142 cmd.Flags().StringVar(&stepConfig.AtcResultsFileName, "atcResultsFileName", `ATCResults.xml`, "Specifies output file name for the results from the ATC checks") 143 cmd.Flags().StringVar(&stepConfig.AUnitResultsFileName, "aUnitResultsFileName", `AUnitResults.xml`, "Specifies output file name for the results from the AUnit tests") 144 145 cmd.MarkFlagRequired("username") 146 cmd.MarkFlagRequired("password") 147 cmd.MarkFlagRequired("host") 148 cmd.MarkFlagRequired("repository") 149 cmd.MarkFlagRequired("client") 150 cmd.MarkFlagRequired("workspace") 151 } 152 153 // retrieve step metadata 154 func gctsExecuteABAPQualityChecksMetadata() config.StepData { 155 var theMetaData = config.StepData{ 156 Metadata: config.StepMetadata{ 157 Name: "gctsExecuteABAPQualityChecks", 158 Aliases: []config.Alias{}, 159 Description: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", 160 }, 161 Spec: config.StepSpec{ 162 Inputs: config.StepInputs{ 163 Secrets: []config.StepSecrets{ 164 {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"}, 165 }, 166 Parameters: []config.StepParameters{ 167 { 168 Name: "username", 169 ResourceRef: []config.ResourceReference{ 170 { 171 Name: "abapCredentialsId", 172 Param: "username", 173 Type: "secret", 174 }, 175 }, 176 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 177 Type: "string", 178 Mandatory: true, 179 Aliases: []config.Alias{}, 180 Default: os.Getenv("PIPER_username"), 181 }, 182 { 183 Name: "password", 184 ResourceRef: []config.ResourceReference{ 185 { 186 Name: "abapCredentialsId", 187 Param: "password", 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_password"), 196 }, 197 { 198 Name: "host", 199 ResourceRef: []config.ResourceReference{}, 200 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 201 Type: "string", 202 Mandatory: true, 203 Aliases: []config.Alias{}, 204 Default: os.Getenv("PIPER_host"), 205 }, 206 { 207 Name: "repository", 208 ResourceRef: []config.ResourceReference{}, 209 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 210 Type: "string", 211 Mandatory: true, 212 Aliases: []config.Alias{}, 213 Default: os.Getenv("PIPER_repository"), 214 }, 215 { 216 Name: "client", 217 ResourceRef: []config.ResourceReference{}, 218 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 219 Type: "string", 220 Mandatory: true, 221 Aliases: []config.Alias{}, 222 Default: os.Getenv("PIPER_client"), 223 }, 224 { 225 Name: "aUnitTest", 226 ResourceRef: []config.ResourceReference{}, 227 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 228 Type: "bool", 229 Mandatory: false, 230 Aliases: []config.Alias{}, 231 Default: true, 232 }, 233 { 234 Name: "atcCheck", 235 ResourceRef: []config.ResourceReference{}, 236 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 237 Type: "bool", 238 Mandatory: false, 239 Aliases: []config.Alias{}, 240 Default: true, 241 }, 242 { 243 Name: "atcVariant", 244 ResourceRef: []config.ResourceReference{}, 245 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 246 Type: "string", 247 Mandatory: false, 248 Aliases: []config.Alias{}, 249 Default: `DEFAULT_REMOTE_REF`, 250 }, 251 { 252 Name: "scope", 253 ResourceRef: []config.ResourceReference{}, 254 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 255 Type: "string", 256 Mandatory: false, 257 Aliases: []config.Alias{}, 258 Default: `repository`, 259 }, 260 { 261 Name: "commit", 262 ResourceRef: []config.ResourceReference{}, 263 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 264 Type: "string", 265 Mandatory: false, 266 Aliases: []config.Alias{}, 267 Default: os.Getenv("PIPER_commit"), 268 }, 269 { 270 Name: "workspace", 271 ResourceRef: []config.ResourceReference{}, 272 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 273 Type: "string", 274 Mandatory: true, 275 Aliases: []config.Alias{}, 276 Default: os.Getenv("PIPER_workspace"), 277 }, 278 { 279 Name: "atcResultsFileName", 280 ResourceRef: []config.ResourceReference{}, 281 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 282 Type: "string", 283 Mandatory: false, 284 Aliases: []config.Alias{}, 285 Default: `ATCResults.xml`, 286 }, 287 { 288 Name: "aUnitResultsFileName", 289 ResourceRef: []config.ResourceReference{}, 290 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 291 Type: "string", 292 Mandatory: false, 293 Aliases: []config.Alias{}, 294 Default: `AUnitResults.xml`, 295 }, 296 }, 297 }, 298 }, 299 } 300 return theMetaData 301 }