github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/abapAddonAssemblyKitReleasePackages_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 "time" 10 11 "github.com/SAP/jenkins-library/pkg/config" 12 "github.com/SAP/jenkins-library/pkg/log" 13 "github.com/SAP/jenkins-library/pkg/piperenv" 14 "github.com/SAP/jenkins-library/pkg/splunk" 15 "github.com/SAP/jenkins-library/pkg/telemetry" 16 "github.com/SAP/jenkins-library/pkg/validation" 17 "github.com/spf13/cobra" 18 ) 19 20 type abapAddonAssemblyKitReleasePackagesOptions struct { 21 AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"` 22 Username string `json:"username,omitempty"` 23 Password string `json:"password,omitempty"` 24 AddonDescriptor string `json:"addonDescriptor,omitempty"` 25 MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"` 26 PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"` 27 } 28 29 type abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment struct { 30 abap struct { 31 addonDescriptor string 32 } 33 } 34 35 func (p *abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment) persist(path, resourceName string) { 36 content := []struct { 37 category string 38 name string 39 value interface{} 40 }{ 41 {category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, 42 } 43 44 errCount := 0 45 for _, param := range content { 46 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 47 if err != nil { 48 log.Entry().WithError(err).Error("Error persisting piper environment.") 49 errCount++ 50 } 51 } 52 if errCount > 0 { 53 log.Entry().Error("failed to persist Piper environment") 54 } 55 } 56 57 // AbapAddonAssemblyKitReleasePackagesCommand This step releases the physical Delivery Packages 58 func AbapAddonAssemblyKitReleasePackagesCommand() *cobra.Command { 59 const STEP_NAME = "abapAddonAssemblyKitReleasePackages" 60 61 metadata := abapAddonAssemblyKitReleasePackagesMetadata() 62 var stepConfig abapAddonAssemblyKitReleasePackagesOptions 63 var startTime time.Time 64 var commonPipelineEnvironment abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment 65 var logCollector *log.CollectorHook 66 var splunkClient *splunk.Splunk 67 telemetryClient := &telemetry.Telemetry{} 68 69 var createAbapAddonAssemblyKitReleasePackagesCmd = &cobra.Command{ 70 Use: STEP_NAME, 71 Short: "This step releases the physical Delivery Packages", 72 Long: `This step takes the list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. 73 The physical Delivery Packages in status āLā are released. The new status "R"eleased is written back to the addonDescriptor in the commonPipelineEnvironment. 74 <br /> 75 For Terminology refer to the [Scenario Description](https://www.project-piper.io/scenarios/abapEnvironmentAddons/).`, 76 PreRunE: func(cmd *cobra.Command, _ []string) error { 77 startTime = time.Now() 78 log.SetStepName(STEP_NAME) 79 log.SetVerbose(GeneralConfig.Verbose) 80 81 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 82 83 path, _ := os.Getwd() 84 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 85 log.RegisterHook(fatalHook) 86 87 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 88 if err != nil { 89 log.SetErrorCategory(log.ErrorConfiguration) 90 return err 91 } 92 93 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 94 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 95 log.RegisterHook(&sentryHook) 96 } 97 98 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 99 splunkClient = &splunk.Splunk{} 100 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 101 log.RegisterHook(logCollector) 102 } 103 104 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 105 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 106 } 107 108 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 109 if err != nil { 110 return err 111 } 112 if err = validation.ValidateStruct(stepConfig); err != nil { 113 log.SetErrorCategory(log.ErrorConfiguration) 114 return err 115 } 116 117 return nil 118 }, 119 Run: func(_ *cobra.Command, _ []string) { 120 stepTelemetryData := telemetry.CustomData{} 121 stepTelemetryData.ErrorCode = "1" 122 handler := func() { 123 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 124 config.RemoveVaultSecretFiles() 125 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 126 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 127 stepTelemetryData.PiperCommitHash = GitCommit 128 telemetryClient.SetData(&stepTelemetryData) 129 telemetryClient.Send() 130 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 131 splunkClient.Initialize(GeneralConfig.CorrelationID, 132 GeneralConfig.HookConfig.SplunkConfig.Dsn, 133 GeneralConfig.HookConfig.SplunkConfig.Token, 134 GeneralConfig.HookConfig.SplunkConfig.Index, 135 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 136 splunkClient.Send(telemetryClient.GetData(), logCollector) 137 } 138 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 139 splunkClient.Initialize(GeneralConfig.CorrelationID, 140 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 141 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 142 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 143 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 144 splunkClient.Send(telemetryClient.GetData(), logCollector) 145 } 146 } 147 log.DeferExitHandler(handler) 148 defer handler() 149 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 150 abapAddonAssemblyKitReleasePackages(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 151 stepTelemetryData.ErrorCode = "0" 152 log.Entry().Info("SUCCESS") 153 }, 154 } 155 156 addAbapAddonAssemblyKitReleasePackagesFlags(createAbapAddonAssemblyKitReleasePackagesCmd, &stepConfig) 157 return createAbapAddonAssemblyKitReleasePackagesCmd 158 } 159 160 func addAbapAddonAssemblyKitReleasePackagesFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitReleasePackagesOptions) { 161 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", `https://apps.support.sap.com`, "Base URL to the Addon Assembly Kit as a Service (AAKaaS) system") 162 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system") 163 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system") 164 cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions") 165 cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 5, "Maximum runtime for status polling in minutes") 166 cmd.Flags().IntVar(&stepConfig.PollingIntervalInSeconds, "pollingIntervalInSeconds", 30, "Wait time in seconds between polling calls") 167 168 cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint") 169 cmd.MarkFlagRequired("username") 170 cmd.MarkFlagRequired("password") 171 cmd.MarkFlagRequired("addonDescriptor") 172 } 173 174 // retrieve step metadata 175 func abapAddonAssemblyKitReleasePackagesMetadata() config.StepData { 176 var theMetaData = config.StepData{ 177 Metadata: config.StepMetadata{ 178 Name: "abapAddonAssemblyKitReleasePackages", 179 Aliases: []config.Alias{}, 180 Description: "This step releases the physical Delivery Packages", 181 }, 182 Spec: config.StepSpec{ 183 Inputs: config.StepInputs{ 184 Secrets: []config.StepSecrets{ 185 {Name: "abapAddonAssemblyKitCredentialsId", Description: "Credential stored in Jenkins for the Addon Assembly Kit as a Service (AAKaaS) system", Type: "jenkins"}, 186 }, 187 Parameters: []config.StepParameters{ 188 { 189 Name: "abapAddonAssemblyKitEndpoint", 190 ResourceRef: []config.ResourceReference{}, 191 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 192 Type: "string", 193 Mandatory: true, 194 Aliases: []config.Alias{}, 195 Default: `https://apps.support.sap.com`, 196 }, 197 { 198 Name: "username", 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_username"), 205 }, 206 { 207 Name: "password", 208 ResourceRef: []config.ResourceReference{}, 209 Scope: []string{"PARAMETERS"}, 210 Type: "string", 211 Mandatory: true, 212 Aliases: []config.Alias{}, 213 Default: os.Getenv("PIPER_password"), 214 }, 215 { 216 Name: "addonDescriptor", 217 ResourceRef: []config.ResourceReference{ 218 { 219 Name: "commonPipelineEnvironment", 220 Param: "abap/addonDescriptor", 221 }, 222 }, 223 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 224 Type: "string", 225 Mandatory: true, 226 Aliases: []config.Alias{}, 227 Default: os.Getenv("PIPER_addonDescriptor"), 228 }, 229 { 230 Name: "maxRuntimeInMinutes", 231 ResourceRef: []config.ResourceReference{}, 232 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 233 Type: "int", 234 Mandatory: false, 235 Aliases: []config.Alias{}, 236 Default: 5, 237 }, 238 { 239 Name: "pollingIntervalInSeconds", 240 ResourceRef: []config.ResourceReference{}, 241 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 242 Type: "int", 243 Mandatory: false, 244 Aliases: []config.Alias{}, 245 Default: 30, 246 }, 247 }, 248 }, 249 Outputs: config.StepOutputs{ 250 Resources: []config.StepResources{ 251 { 252 Name: "commonPipelineEnvironment", 253 Type: "piperEnvironment", 254 Parameters: []map[string]interface{}{ 255 {"name": "abap/addonDescriptor"}, 256 }, 257 }, 258 }, 259 }, 260 }, 261 } 262 return theMetaData 263 }