You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	Local scopeg cts execute abap unit test (#3563)
* Adjust local changed objects with commit history * fix the righ history entry * fix for local packages commit history * Adapt unit tests and fix for retry after 500 * Rename gctsExecuteABAPUnitTests to gctsExecuteABAPQualityChecks * Add unit test file for gCTSExecuteABAPUnitTest * add a test step * gcts Test change files * Add unit test for gCTS test * adapt gctsTEST * deletegcts * command * maintain old step * Adapt changes to documentation * fix for go generate
This commit is contained in:
		
							
								
								
									
										1896
									
								
								cmd/gctsExecuteABAPQualityChecks.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1896
									
								
								cmd/gctsExecuteABAPQualityChecks.go
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										301
									
								
								cmd/gctsExecuteABAPQualityChecks_generated.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										301
									
								
								cmd/gctsExecuteABAPQualityChecks_generated.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,301 @@ | ||||
| // Code generated by piper's step-generator. DO NOT EDIT. | ||||
|  | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/SAP/jenkins-library/pkg/config" | ||||
| 	"github.com/SAP/jenkins-library/pkg/log" | ||||
| 	"github.com/SAP/jenkins-library/pkg/splunk" | ||||
| 	"github.com/SAP/jenkins-library/pkg/telemetry" | ||||
| 	"github.com/SAP/jenkins-library/pkg/validation" | ||||
| 	"github.com/spf13/cobra" | ||||
| ) | ||||
|  | ||||
| type gctsExecuteABAPQualityChecksOptions struct { | ||||
| 	Username             string `json:"username,omitempty"` | ||||
| 	Password             string `json:"password,omitempty"` | ||||
| 	Host                 string `json:"host,omitempty"` | ||||
| 	Repository           string `json:"repository,omitempty"` | ||||
| 	Client               string `json:"client,omitempty"` | ||||
| 	AUnitTest            bool   `json:"aUnitTest,omitempty"` | ||||
| 	AtcCheck             bool   `json:"atcCheck,omitempty"` | ||||
| 	AtcVariant           string `json:"atcVariant,omitempty"` | ||||
| 	Scope                string `json:"scope,omitempty"` | ||||
| 	Commit               string `json:"commit,omitempty"` | ||||
| 	Workspace            string `json:"workspace,omitempty"` | ||||
| 	AtcResultsFileName   string `json:"atcResultsFileName,omitempty"` | ||||
| 	AUnitResultsFileName string `json:"aUnitResultsFileName,omitempty"` | ||||
| } | ||||
|  | ||||
| // GctsExecuteABAPQualityChecksCommand Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope. | ||||
| func GctsExecuteABAPQualityChecksCommand() *cobra.Command { | ||||
| 	const STEP_NAME = "gctsExecuteABAPQualityChecks" | ||||
|  | ||||
| 	metadata := gctsExecuteABAPQualityChecksMetadata() | ||||
| 	var stepConfig gctsExecuteABAPQualityChecksOptions | ||||
| 	var startTime time.Time | ||||
| 	var logCollector *log.CollectorHook | ||||
| 	var splunkClient *splunk.Splunk | ||||
| 	telemetryClient := &telemetry.Telemetry{} | ||||
|  | ||||
| 	var createGctsExecuteABAPQualityChecksCmd = &cobra.Command{ | ||||
| 		Use:   STEP_NAME, | ||||
| 		Short: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", | ||||
| 		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. | ||||
| 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. | ||||
| By default, both checks are executed. | ||||
| 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. | ||||
| To make the findings visible in Jenkins interface, you will need to use step recordIssues. An example will be shown in the Example section. | ||||
| <br /> | ||||
| You can use this step as of SAP S/4HANA 2020.`, | ||||
| 		PreRunE: func(cmd *cobra.Command, _ []string) error { | ||||
| 			startTime = time.Now() | ||||
| 			log.SetStepName(STEP_NAME) | ||||
| 			log.SetVerbose(GeneralConfig.Verbose) | ||||
|  | ||||
| 			GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) | ||||
|  | ||||
| 			path, _ := os.Getwd() | ||||
| 			fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} | ||||
| 			log.RegisterHook(fatalHook) | ||||
|  | ||||
| 			err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) | ||||
| 			if err != nil { | ||||
| 				log.SetErrorCategory(log.ErrorConfiguration) | ||||
| 				return err | ||||
| 			} | ||||
| 			log.RegisterSecret(stepConfig.Username) | ||||
| 			log.RegisterSecret(stepConfig.Password) | ||||
|  | ||||
| 			if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { | ||||
| 				sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) | ||||
| 				log.RegisterHook(&sentryHook) | ||||
| 			} | ||||
|  | ||||
| 			if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { | ||||
| 				splunkClient = &splunk.Splunk{} | ||||
| 				logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} | ||||
| 				log.RegisterHook(logCollector) | ||||
| 			} | ||||
|  | ||||
| 			validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			if err = validation.ValidateStruct(stepConfig); err != nil { | ||||
| 				log.SetErrorCategory(log.ErrorConfiguration) | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 		Run: func(_ *cobra.Command, _ []string) { | ||||
| 			stepTelemetryData := telemetry.CustomData{} | ||||
| 			stepTelemetryData.ErrorCode = "1" | ||||
| 			handler := func() { | ||||
| 				config.RemoveVaultSecretFiles() | ||||
| 				stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) | ||||
| 				stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() | ||||
| 				stepTelemetryData.PiperCommitHash = GitCommit | ||||
| 				telemetryClient.SetData(&stepTelemetryData) | ||||
| 				telemetryClient.Send() | ||||
| 				if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { | ||||
| 					splunkClient.Send(telemetryClient.GetData(), logCollector) | ||||
| 				} | ||||
| 			} | ||||
| 			log.DeferExitHandler(handler) | ||||
| 			defer handler() | ||||
| 			telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) | ||||
| 			if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { | ||||
| 				splunkClient.Initialize(GeneralConfig.CorrelationID, | ||||
| 					GeneralConfig.HookConfig.SplunkConfig.Dsn, | ||||
| 					GeneralConfig.HookConfig.SplunkConfig.Token, | ||||
| 					GeneralConfig.HookConfig.SplunkConfig.Index, | ||||
| 					GeneralConfig.HookConfig.SplunkConfig.SendLogs) | ||||
| 			} | ||||
| 			gctsExecuteABAPQualityChecks(stepConfig, &stepTelemetryData) | ||||
| 			stepTelemetryData.ErrorCode = "0" | ||||
| 			log.Entry().Info("SUCCESS") | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	addGctsExecuteABAPQualityChecksFlags(createGctsExecuteABAPQualityChecksCmd, &stepConfig) | ||||
| 	return createGctsExecuteABAPQualityChecksCmd | ||||
| } | ||||
|  | ||||
| func addGctsExecuteABAPQualityChecksFlags(cmd *cobra.Command, stepConfig *gctsExecuteABAPQualityChecksOptions) { | ||||
| 	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.") | ||||
| 	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.") | ||||
| 	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.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Name (ID) of the local repository on the ABAP system") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "Client of the ABAP system in which you want to execute the checks") | ||||
| 	cmd.Flags().BoolVar(&stepConfig.AUnitTest, "aUnitTest", true, "Indication whether you want to execute the unit test checks.") | ||||
| 	cmd.Flags().BoolVar(&stepConfig.AtcCheck, "atcCheck", true, "Indication whether you want to execute the ATC checks.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AtcVariant, "atcVariant", `DEFAULT_REMOTE_REF`, "Variant for ATC checks") | ||||
| 	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") | ||||
| 	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.") | ||||
| 	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>/") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AtcResultsFileName, "atcResultsFileName", `ATCResults.xml`, "Specifies output file name for the results from the ATC checks") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AUnitResultsFileName, "aUnitResultsFileName", `AUnitResults.xml`, "Specifies output file name for the results from the AUnit tests") | ||||
|  | ||||
| 	cmd.MarkFlagRequired("username") | ||||
| 	cmd.MarkFlagRequired("password") | ||||
| 	cmd.MarkFlagRequired("host") | ||||
| 	cmd.MarkFlagRequired("repository") | ||||
| 	cmd.MarkFlagRequired("client") | ||||
| 	cmd.MarkFlagRequired("workspace") | ||||
| } | ||||
|  | ||||
| // retrieve step metadata | ||||
| func gctsExecuteABAPQualityChecksMetadata() config.StepData { | ||||
| 	var theMetaData = config.StepData{ | ||||
| 		Metadata: config.StepMetadata{ | ||||
| 			Name:        "gctsExecuteABAPQualityChecks", | ||||
| 			Aliases:     []config.Alias{}, | ||||
| 			Description: "Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.", | ||||
| 		}, | ||||
| 		Spec: config.StepSpec{ | ||||
| 			Inputs: config.StepInputs{ | ||||
| 				Secrets: []config.StepSecrets{ | ||||
| 					{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"}, | ||||
| 				}, | ||||
| 				Parameters: []config.StepParameters{ | ||||
| 					{ | ||||
| 						Name: "username", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "abapCredentialsId", | ||||
| 								Param: "username", | ||||
| 								Type:  "secret", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 						Default:   os.Getenv("PIPER_username"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name: "password", | ||||
| 						ResourceRef: []config.ResourceReference{ | ||||
| 							{ | ||||
| 								Name:  "abapCredentialsId", | ||||
| 								Param: "password", | ||||
| 								Type:  "secret", | ||||
| 							}, | ||||
| 						}, | ||||
| 						Scope:     []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:      "string", | ||||
| 						Mandatory: true, | ||||
| 						Aliases:   []config.Alias{}, | ||||
| 						Default:   os.Getenv("PIPER_password"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "host", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_host"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "repository", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_repository"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "client", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_client"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "aUnitTest", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "bool", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     true, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "atcCheck", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "bool", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     true, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "atcVariant", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     `DEFAULT_REMOTE_REF`, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "scope", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     `repository`, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "commit", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_commit"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "workspace", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   true, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     os.Getenv("PIPER_workspace"), | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "atcResultsFileName", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     `ATCResults.xml`, | ||||
| 					}, | ||||
| 					{ | ||||
| 						Name:        "aUnitResultsFileName", | ||||
| 						ResourceRef: []config.ResourceReference{}, | ||||
| 						Scope:       []string{"PARAMETERS", "STAGES", "STEPS"}, | ||||
| 						Type:        "string", | ||||
| 						Mandatory:   false, | ||||
| 						Aliases:     []config.Alias{}, | ||||
| 						Default:     `AUnitResults.xml`, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	return theMetaData | ||||
| } | ||||
							
								
								
									
										17
									
								
								cmd/gctsExecuteABAPQualityChecks_generated_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cmd/gctsExecuteABAPQualityChecks_generated_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package cmd | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestGctsExecuteABAPQualityChecksCommand(t *testing.T) { | ||||
| 	t.Parallel() | ||||
|  | ||||
| 	testCmd := GctsExecuteABAPQualityChecksCommand() | ||||
|  | ||||
| 	// only high level testing performed - details are tested in step generation procedure | ||||
| 	assert.Equal(t, "gctsExecuteABAPQualityChecks", testCmd.Use, "command name incorrect") | ||||
|  | ||||
| } | ||||
							
								
								
									
										1853
									
								
								cmd/gctsExecuteABAPQualityChecks_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1853
									
								
								cmd/gctsExecuteABAPQualityChecks_test.go
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -136,8 +136,8 @@ func addGctsExecuteABAPUnitTestsFlags(cmd *cobra.Command, stepConfig *gctsExecut | ||||
| 	cmd.Flags().BoolVar(&stepConfig.AUnitTest, "aUnitTest", true, "Indication whether you want to execute the unit test checks.") | ||||
| 	cmd.Flags().BoolVar(&stepConfig.AtcCheck, "atcCheck", true, "Indication whether you want to execute the ATC checks.") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AtcVariant, "atcVariant", `DEFAULT_REMOTE_REF`, "Variant for ATC checks") | ||||
| 	cmd.Flags().StringVar(&stepConfig.Scope, "scope", `repository`, "Scope of objects for which you want to execute the checks:\n\n * localChangedObjects - object delta between the commit that triggered the pipeline and the current commit 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 between the commit that triggered the pipeline and the current commit 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") | ||||
| 	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 localChangedObjects, remoteChangedObjects, localChangedPackages and remoteChangedPackages secifying a commit it's mandatory.") | ||||
| 	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") | ||||
| 	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.") | ||||
| 	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>/") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AtcResultsFileName, "atcResultsFileName", `ATCResults.xml`, "Specifies output file name for the results from the ATC checks") | ||||
| 	cmd.Flags().StringVar(&stepConfig.AUnitResultsFileName, "aUnitResultsFileName", `AUnitResults.xml`, "Specifies output file name for the results from the AUnit tests") | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -45,6 +45,7 @@ func GetAllStepMetadata() map[string]config.StepData { | ||||
| 		"gctsCloneRepository":                       gctsCloneRepositoryMetadata(), | ||||
| 		"gctsCreateRepository":                      gctsCreateRepositoryMetadata(), | ||||
| 		"gctsDeploy":                                gctsDeployMetadata(), | ||||
| 		"gctsExecuteABAPQualityChecks":              gctsExecuteABAPQualityChecksMetadata(), | ||||
| 		"gctsExecuteABAPUnitTests":                  gctsExecuteABAPUnitTestsMetadata(), | ||||
| 		"gctsRollback":                              gctsRollbackMetadata(), | ||||
| 		"githubCheckBranchProtection":               githubCheckBranchProtectionMetadata(), | ||||
|   | ||||
| @@ -124,6 +124,7 @@ func Execute() { | ||||
| 	rootCmd.AddCommand(NpmExecuteScriptsCommand()) | ||||
| 	rootCmd.AddCommand(NpmExecuteLintCommand()) | ||||
| 	rootCmd.AddCommand(GctsCreateRepositoryCommand()) | ||||
| 	rootCmd.AddCommand(GctsExecuteABAPQualityChecksCommand()) | ||||
| 	rootCmd.AddCommand(GctsExecuteABAPUnitTestsCommand()) | ||||
| 	rootCmd.AddCommand(GctsDeployCommand()) | ||||
| 	rootCmd.AddCommand(MalwareExecuteScanCommand()) | ||||
|   | ||||
							
								
								
									
										123
									
								
								documentation/docs/steps/gctsExecuteABAPQualityChecks.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								documentation/docs/steps/gctsExecuteABAPQualityChecks.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,123 @@ | ||||
| # ${docGenStepName} | ||||
|  | ||||
| ## ${docGenDescription} | ||||
|  | ||||
| ## Prerequisites | ||||
|  | ||||
| * [ATC](https://help.sap.com/viewer/c238d694b825421f940829321ffa326a/202110.000/en-US/4ec5711c6e391014adc9fffe4e204223.html) checks are enabled in transaction ATC in the ABAP systems where you want to use the step. | ||||
| * [gCTS](https://help.sap.com/viewer/4a368c163b08418890a406d413933ba7/latest/en-US/26c9c6c5a89244cb9506c253d36c3fda.html) is available and configured in the ABAP systems where you want to use the step. | ||||
| * The [Warnings-Next-Generation](https://plugins.jenkins.io/warnings-ng/) Plugin is installed in Jenkins. | ||||
|  | ||||
| ## ${docGenParameters} | ||||
|  | ||||
| ## ${docGenConfiguration} | ||||
|  | ||||
| ## ${docJenkinsPluginDependencies} | ||||
|  | ||||
| ## Example | ||||
|  | ||||
| Example configuration for the use in a Jenkinsfile. | ||||
|  | ||||
| ```groovy | ||||
| gctsExecuteABAPQualityChecks( | ||||
|   script: this, | ||||
|   host: 'https://abap.server.com:port', | ||||
|   client: '000', | ||||
|   abapCredentialsId: 'ABAPUserPasswordCredentialsId', | ||||
|   repository: 'myrepo', | ||||
|   scope: 'remoteChangedObjects', | ||||
|   commit: "${GIT_COMMIT}", | ||||
|   workspace: "${WORKSPACE}" | ||||
|  | ||||
|   ) | ||||
| ``` | ||||
|  | ||||
| Example configuration for the use in a yaml config file (such as `.pipeline/config.yaml`). | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   <...> | ||||
|   gctsExecuteABAPQualityChecks: | ||||
|     host: 'https://abap.server.com:port' | ||||
|     client: '000' | ||||
|     abapCredentialsId: 'ABAPUserPasswordCredentialsId' | ||||
|     repository: 'myrepo' | ||||
|     scope: 'remoteChangedObjects' | ||||
|     commit: '38abb4814ae46b98e8e6c3e718cf1782afa9ca90' | ||||
|     workspace: '/var/jenkins_home/workspace/myFirstPipeline' | ||||
| ``` | ||||
|  | ||||
| Example configuration when you define scope: *repository* or *packages*. For these two cases you do not need to specify a *commit*. | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   <...> | ||||
|   gctsExecuteABAPQualityChecks: | ||||
|     host: 'https://abap.server.com:port' | ||||
|     client: '000' | ||||
|     abapCredentialsId: 'ABAPUserPasswordCredentialsId' | ||||
|     repository: 'myrepo' | ||||
|     scope: 'repository' | ||||
|     workspace: '/var/jenkins_home/workspace/myFirstPipeline' | ||||
| ``` | ||||
|  | ||||
| Example configuration when you want to execute only ABAP Unit Test. | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   <...> | ||||
|   gctsExecuteABAPQualityChecks: | ||||
|     host: 'https://abap.server.com:port' | ||||
|     client: '000' | ||||
|     abapCredentialsId: 'ABAPUserPasswordCredentialsId' | ||||
|     repository: 'myrepo' | ||||
|     atcCheck: false | ||||
|     scope: 'packages' | ||||
|     workspace: '/var/jenkins_home/workspace/myFirstPipeline' | ||||
| ``` | ||||
|  | ||||
| Example configuration for the use of *recordIssue* step to make the findings visible in Jenkins interface. | ||||
|  | ||||
| ```groovy | ||||
| stage('ABAP Unit Tests') { | ||||
|   steps{ | ||||
|  | ||||
|    script{ | ||||
|  | ||||
|      try{ | ||||
|            gctsExecuteABAPQualityChecks( | ||||
|               script: this, | ||||
|               commit: "${GIT_COMMIT}", | ||||
|               workspace: "${WORKSPACE}") | ||||
|         } | ||||
|           catch (Exception ex) { | ||||
|             currentBuild.result = 'FAILURE' | ||||
|             unstable(message: "${STAGE_NAME} is unstable") | ||||
|              } | ||||
|  | ||||
|         } | ||||
|       } | ||||
|     } | ||||
| stage('Results in Checkstyle') { | ||||
|   steps{ | ||||
|  | ||||
|      recordIssues( | ||||
|           enabledForFailure: true, aggregatingResults: true, | ||||
|           tools: [checkStyle(pattern: 'ATCResults.xml', reportEncoding: 'UTF8'),checkStyle(pattern: 'AUnitResults.xml', reportEncoding: 'UTF8')] | ||||
|        ) | ||||
|  | ||||
|       } | ||||
|     } | ||||
|  | ||||
| } | ||||
| ``` | ||||
|  | ||||
| **Note:** If you have disabled *atcCheck* or *aUnitTest*, than you also need to remove the corresponding *ATCResults.xml* or *AUnitResults.xml* from *recordIssues* step. In the example below the *atcCheck* was disabled, so *ATCResults.xml* was removed. | ||||
|  | ||||
| ```groovy | ||||
| recordIssues( | ||||
|   enabledForFailure: true, aggregatingResults: true, | ||||
|   tools: [checkStyle(pattern: 'AUnitResults.xml', reportEncoding: 'UTF8')] | ||||
|  | ||||
| ) | ||||
| ``` | ||||
| @@ -25,7 +25,7 @@ gctsExecuteABAPUnitTests( | ||||
|   client: '000', | ||||
|   abapCredentialsId: 'ABAPUserPasswordCredentialsId', | ||||
|   repository: 'myrepo', | ||||
|   scope: 'localChangedObjects', | ||||
|   scope: 'remoteChangedObjects', | ||||
|   commit: "${GIT_COMMIT}", | ||||
|   workspace: "${WORKSPACE}" | ||||
|  | ||||
|   | ||||
| @@ -95,7 +95,7 @@ nav: | ||||
|         - gctsCloneRepository: steps/gctsCloneRepository.md | ||||
|         - gctsCreateRepository: steps/gctsCreateRepository.md | ||||
|         - gctsDeploy: steps/gctsDeploy.md | ||||
|         - gctsExecuteABAPUnitTests: steps/gctsExecuteABAPUnitTests.md | ||||
|         - gctsExecuteABAPQualityChecks: steps/gctsExecuteABAPQualityChecks.md | ||||
|         - gctsRollback: steps/gctsRollback.md | ||||
|         - githubCheckBranchProtection: steps/githubCheckBranchProtection.md | ||||
|         - githubCommentIssue: steps/githubCommentIssue.md | ||||
| @@ -171,6 +171,7 @@ nav: | ||||
|         - checkChangeInDevelopment: steps/checkChangeInDevelopment.md | ||||
|         - npmExecute: steps/npmExecute.md | ||||
|         - transportRequestUploadFile: steps/transportRequestUploadFile.md | ||||
|         - gctsExecuteABAPUnitTests: steps/gctsExecuteABAPUnitTests.md | ||||
|     - 'Command line tool': cli/index.md | ||||
|  | ||||
| theme: | ||||
|   | ||||
							
								
								
									
										150
									
								
								resources/metadata/gctsExecuteABAPQualityChecks.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								resources/metadata/gctsExecuteABAPQualityChecks.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,150 @@ | ||||
| metadata: | ||||
|   name: gctsExecuteABAPQualityChecks | ||||
|   description: Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope. | ||||
|   longDescription: | | ||||
|     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. | ||||
|     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. | ||||
|     By default, both checks are executed. | ||||
|     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. | ||||
|     To make the findings visible in Jenkins interface, you will need to use step recordIssues. An example will be shown in the Example section. | ||||
|     <br /> | ||||
|     You can use this step as of SAP S/4HANA 2020. | ||||
|  | ||||
| spec: | ||||
|   inputs: | ||||
|     secrets: | ||||
|       - 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 | ||||
|     params: | ||||
|       - name: username | ||||
|         type: string | ||||
|         description: 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. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|         resourceRef: | ||||
|           - name: abapCredentialsId | ||||
|             type: secret | ||||
|             param: username | ||||
|       - name: password | ||||
|         type: string | ||||
|         description: 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. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|         secret: true | ||||
|         resourceRef: | ||||
|           - name: abapCredentialsId | ||||
|             type: secret | ||||
|             param: password | ||||
|       - name: host | ||||
|         type: string | ||||
|         description: Protocol and host of the ABAP system, including the port. Please provide in the format <protocol>://<host>:<port>. Supported protocols are http and https. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: repository | ||||
|         type: string | ||||
|         description: Name (ID) of the local repository on the ABAP system | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: client | ||||
|         type: string | ||||
|         description: Client of the ABAP system in which you want to execute the checks | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: aUnitTest | ||||
|         type: bool | ||||
|         default: true | ||||
|         description: Indication whether you want to execute the unit test checks. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|       - name: atcCheck | ||||
|         type: bool | ||||
|         default: true | ||||
|         description: Indication whether you want to execute the ATC checks. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|       - name: atcVariant | ||||
|         type: string | ||||
|         default: "DEFAULT_REMOTE_REF" | ||||
|         description: Variant for ATC checks | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|       - name: scope | ||||
|         type: string | ||||
|         default: repository | ||||
|         enum: | ||||
|           - localChangedObjects | ||||
|           - remoteChangedObjects | ||||
|           - localChangedPackages | ||||
|           - remoteChangedPackages | ||||
|           - repository | ||||
|           - packages | ||||
|         description: | | ||||
|            Scope of objects for which you want to execute the checks: | ||||
|  | ||||
|             * localChangedObjects - object delta derived from last activity in the local repository. The checks are executed for the individual objects. | ||||
|             * 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. | ||||
|             * localChangedPackages - object delta derived from last activity in the local repository. All objects are resolved into packages. The checks are executed for the packages. | ||||
|             * 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. | ||||
|             * 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. | ||||
|             * packages - all packages that are part of the local repository . The checks are executed for the packages. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|       - name: commit | ||||
|         type: string | ||||
|         description: 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. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: false | ||||
|       - name: workspace | ||||
|         type: string | ||||
|         description: 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>/ | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: true | ||||
|       - name: atcResultsFileName | ||||
|         type: string | ||||
|         description: Specifies output file name for the results from the ATC checks | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: false | ||||
|         default: "ATCResults.xml" | ||||
|       - name: aUnitResultsFileName | ||||
|         type: string | ||||
|         description: Specifies output file name for the results from the AUnit tests | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|           - STEPS | ||||
|         mandatory: false | ||||
|         default: "AUnitResults.xml" | ||||
| @@ -104,9 +104,9 @@ spec: | ||||
|         description: | | ||||
|            Scope of objects for which you want to execute the checks: | ||||
|  | ||||
|             * localChangedObjects - object delta between the commit that triggered the pipeline and the current commit in the local repository. The checks are executed for the individual objects. | ||||
|             * localChangedObjects - object delta derived from last activity in the local repository. The checks are executed for the individual objects. | ||||
|             * 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. | ||||
|             * localChangedPackages - object delta between the commit that triggered the pipeline and the current commit in the local repository.  All objects are resolved into packages. The checks are executed for the packages. | ||||
|             * localChangedPackages - object delta derived from last activity in the local repository. All objects are resolved into packages. The checks are executed for the packages. | ||||
|             * 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. | ||||
|             * 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. | ||||
|             * packages - all packages that are part of the local repository . The checks are executed for the packages. | ||||
| @@ -116,7 +116,7 @@ spec: | ||||
|           - STEPS | ||||
|       - name: commit | ||||
|         type: string | ||||
|         description: ID of the commit that triggered the pipeline or any other commit to compare objects. For scopes localChangedObjects, remoteChangedObjects, localChangedPackages and remoteChangedPackages secifying a commit it's mandatory. | ||||
|         description: 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. | ||||
|         scope: | ||||
|           - PARAMETERS | ||||
|           - STAGES | ||||
|   | ||||
| @@ -168,6 +168,7 @@ public class CommonStepsTest extends BasePiperTest{ | ||||
|         'sonarExecuteScan', //implementing new golang pattern without fields | ||||
|         'gctsCreateRepository', //implementing new golang pattern without fields | ||||
|         'gctsRollback', //implementing new golang pattern without fields | ||||
|         'gctsExecuteABAPQualityChecks', //implementing new golang pattern without fields | ||||
|         'gctsExecuteABAPUnitTests', //implementing new golang pattern without fields | ||||
|         'gctsCloneRepository', //implementing new golang pattern without fields | ||||
|         'fortifyExecuteScan', //implementing new golang pattern without fields | ||||
|   | ||||
							
								
								
									
										11
									
								
								vars/gctsExecuteABAPQualityChecks.groovy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								vars/gctsExecuteABAPQualityChecks.groovy
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| import groovy.transform.Field | ||||
|  | ||||
| @Field String STEP_NAME = getClass().getName() | ||||
| @Field String METADATA_FILE = 'metadata/gctsExecuteABAPQualityChecks.yaml' | ||||
|  | ||||
| void call(Map parameters = [:]) { | ||||
|         List credentials = [ | ||||
|         [type: 'usernamePassword', id: 'abapCredentialsId', env: ['PIPER_username', 'PIPER_password']] | ||||
|         ] | ||||
|         piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user