github.com/jaylevin/jenkins-library@v1.230.4/cmd/abapEnvironmentAssemblePackages_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 abapEnvironmentAssemblePackagesOptions struct { 21 CfAPIEndpoint string `json:"cfApiEndpoint,omitempty"` 22 CfOrg string `json:"cfOrg,omitempty"` 23 CfSpace string `json:"cfSpace,omitempty"` 24 CfServiceInstance string `json:"cfServiceInstance,omitempty"` 25 CfServiceKeyName string `json:"cfServiceKeyName,omitempty"` 26 Host string `json:"host,omitempty"` 27 Username string `json:"username,omitempty"` 28 Password string `json:"password,omitempty"` 29 AddonDescriptor string `json:"addonDescriptor,omitempty"` 30 MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"` 31 PollIntervalsInMilliseconds int `json:"pollIntervalsInMilliseconds,omitempty"` 32 CertificateNames []string `json:"certificateNames,omitempty"` 33 } 34 35 type abapEnvironmentAssemblePackagesCommonPipelineEnvironment struct { 36 abap struct { 37 addonDescriptor string 38 } 39 } 40 41 func (p *abapEnvironmentAssemblePackagesCommonPipelineEnvironment) persist(path, resourceName string) { 42 content := []struct { 43 category string 44 name string 45 value interface{} 46 }{ 47 {category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, 48 } 49 50 errCount := 0 51 for _, param := range content { 52 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 53 if err != nil { 54 log.Entry().WithError(err).Error("Error persisting piper environment.") 55 errCount++ 56 } 57 } 58 if errCount > 0 { 59 log.Entry().Error("failed to persist Piper environment") 60 } 61 } 62 63 // AbapEnvironmentAssemblePackagesCommand Assembly of installation, support package or patch in SAP Cloud Platform ABAP Environment system 64 func AbapEnvironmentAssemblePackagesCommand() *cobra.Command { 65 const STEP_NAME = "abapEnvironmentAssemblePackages" 66 67 metadata := abapEnvironmentAssemblePackagesMetadata() 68 var stepConfig abapEnvironmentAssemblePackagesOptions 69 var startTime time.Time 70 var commonPipelineEnvironment abapEnvironmentAssemblePackagesCommonPipelineEnvironment 71 var logCollector *log.CollectorHook 72 var splunkClient *splunk.Splunk 73 telemetryClient := &telemetry.Telemetry{} 74 75 var createAbapEnvironmentAssemblePackagesCmd = &cobra.Command{ 76 Use: STEP_NAME, 77 Short: "Assembly of installation, support package or patch in SAP Cloud Platform ABAP Environment system", 78 Long: `This step runs the assembly of a list of provided [installations, support packages or patches](https://help.sap.com/viewer/9043aa5d2f834ad385e1cdfdadc06b6f/LATEST/en-US/9a81f55473568c77e10000000a174cb4.html) in SAP Cloud 79 Platform ABAP Environment system and saves the corresponding [SAR archive](https://launchpad.support.sap.com/#/notes/212876) to the filesystem.`, 80 PreRunE: func(cmd *cobra.Command, _ []string) error { 81 startTime = time.Now() 82 log.SetStepName(STEP_NAME) 83 log.SetVerbose(GeneralConfig.Verbose) 84 85 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 86 87 path, _ := os.Getwd() 88 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 89 log.RegisterHook(fatalHook) 90 91 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 92 if err != nil { 93 log.SetErrorCategory(log.ErrorConfiguration) 94 return err 95 } 96 log.RegisterSecret(stepConfig.Username) 97 log.RegisterSecret(stepConfig.Password) 98 99 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 100 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 101 log.RegisterHook(&sentryHook) 102 } 103 104 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 105 splunkClient = &splunk.Splunk{} 106 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 107 log.RegisterHook(logCollector) 108 } 109 110 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 111 if err != nil { 112 return err 113 } 114 if err = validation.ValidateStruct(stepConfig); err != nil { 115 log.SetErrorCategory(log.ErrorConfiguration) 116 return err 117 } 118 119 return nil 120 }, 121 Run: func(_ *cobra.Command, _ []string) { 122 stepTelemetryData := telemetry.CustomData{} 123 stepTelemetryData.ErrorCode = "1" 124 handler := func() { 125 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 126 config.RemoveVaultSecretFiles() 127 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 128 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 129 stepTelemetryData.PiperCommitHash = GitCommit 130 telemetryClient.SetData(&stepTelemetryData) 131 telemetryClient.Send() 132 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 133 splunkClient.Send(telemetryClient.GetData(), logCollector) 134 } 135 } 136 log.DeferExitHandler(handler) 137 defer handler() 138 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 139 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 140 splunkClient.Initialize(GeneralConfig.CorrelationID, 141 GeneralConfig.HookConfig.SplunkConfig.Dsn, 142 GeneralConfig.HookConfig.SplunkConfig.Token, 143 GeneralConfig.HookConfig.SplunkConfig.Index, 144 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 145 } 146 abapEnvironmentAssemblePackages(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 147 stepTelemetryData.ErrorCode = "0" 148 log.Entry().Info("SUCCESS") 149 }, 150 } 151 152 addAbapEnvironmentAssemblePackagesFlags(createAbapEnvironmentAssemblePackagesCmd, &stepConfig) 153 return createAbapEnvironmentAssemblePackagesCmd 154 } 155 156 func addAbapEnvironmentAssemblePackagesFlags(cmd *cobra.Command, stepConfig *abapEnvironmentAssemblePackagesOptions) { 157 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", os.Getenv("PIPER_cfApiEndpoint"), "Cloud Foundry API endpoint") 158 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry target organization") 159 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry target space") 160 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Cloud Foundry Service Instance") 161 cmd.Flags().StringVar(&stepConfig.CfServiceKeyName, "cfServiceKeyName", os.Getenv("PIPER_cfServiceKeyName"), "Cloud Foundry Service Key") 162 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP Cloud Platform ABAP Environment system") 163 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") 164 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") 165 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") 166 cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 360, "maximal runtime of the step in minutes") 167 cmd.Flags().IntVar(&stepConfig.PollIntervalsInMilliseconds, "pollIntervalsInMilliseconds", 60000, "wait time in milliseconds till next status request in the backend system") 168 cmd.Flags().StringSliceVar(&stepConfig.CertificateNames, "certificateNames", []string{}, "certificates for the backend system, this certificates needs to be stored in .pipeline/trustStore") 169 170 cmd.MarkFlagRequired("username") 171 cmd.MarkFlagRequired("password") 172 cmd.MarkFlagRequired("addonDescriptor") 173 cmd.MarkFlagRequired("maxRuntimeInMinutes") 174 cmd.MarkFlagRequired("pollIntervalsInMilliseconds") 175 } 176 177 // retrieve step metadata 178 func abapEnvironmentAssemblePackagesMetadata() config.StepData { 179 var theMetaData = config.StepData{ 180 Metadata: config.StepMetadata{ 181 Name: "abapEnvironmentAssemblePackages", 182 Aliases: []config.Alias{}, 183 Description: "Assembly of installation, support package or patch in SAP Cloud Platform ABAP Environment system", 184 }, 185 Spec: config.StepSpec{ 186 Inputs: config.StepInputs{ 187 Secrets: []config.StepSecrets{ 188 {Name: "abapCredentialsId", Description: "Jenkins credentials ID containing user and password to authenticate to the Cloud Platform ABAP Environment system or the Cloud Foundry API", Type: "jenkins", Aliases: []config.Alias{{Name: "cfCredentialsId", Deprecated: false}, {Name: "credentialsId", Deprecated: false}}}, 189 }, 190 Parameters: []config.StepParameters{ 191 { 192 Name: "cfApiEndpoint", 193 ResourceRef: []config.ResourceReference{}, 194 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 195 Type: "string", 196 Mandatory: false, 197 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 198 Default: os.Getenv("PIPER_cfApiEndpoint"), 199 }, 200 { 201 Name: "cfOrg", 202 ResourceRef: []config.ResourceReference{}, 203 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 204 Type: "string", 205 Mandatory: false, 206 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 207 Default: os.Getenv("PIPER_cfOrg"), 208 }, 209 { 210 Name: "cfSpace", 211 ResourceRef: []config.ResourceReference{}, 212 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 213 Type: "string", 214 Mandatory: false, 215 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 216 Default: os.Getenv("PIPER_cfSpace"), 217 }, 218 { 219 Name: "cfServiceInstance", 220 ResourceRef: []config.ResourceReference{}, 221 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 222 Type: "string", 223 Mandatory: false, 224 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 225 Default: os.Getenv("PIPER_cfServiceInstance"), 226 }, 227 { 228 Name: "cfServiceKeyName", 229 ResourceRef: []config.ResourceReference{}, 230 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 231 Type: "string", 232 Mandatory: false, 233 Aliases: []config.Alias{{Name: "cloudFoundry/serviceKey"}, {Name: "cloudFoundry/serviceKeyName"}, {Name: "cfServiceKey"}}, 234 Default: os.Getenv("PIPER_cfServiceKeyName"), 235 }, 236 { 237 Name: "host", 238 ResourceRef: []config.ResourceReference{}, 239 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 240 Type: "string", 241 Mandatory: false, 242 Aliases: []config.Alias{}, 243 Default: os.Getenv("PIPER_host"), 244 }, 245 { 246 Name: "username", 247 ResourceRef: []config.ResourceReference{}, 248 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 249 Type: "string", 250 Mandatory: true, 251 Aliases: []config.Alias{}, 252 Default: os.Getenv("PIPER_username"), 253 }, 254 { 255 Name: "password", 256 ResourceRef: []config.ResourceReference{}, 257 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 258 Type: "string", 259 Mandatory: true, 260 Aliases: []config.Alias{}, 261 Default: os.Getenv("PIPER_password"), 262 }, 263 { 264 Name: "addonDescriptor", 265 ResourceRef: []config.ResourceReference{ 266 { 267 Name: "commonPipelineEnvironment", 268 Param: "abap/addonDescriptor", 269 }, 270 }, 271 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 272 Type: "string", 273 Mandatory: true, 274 Aliases: []config.Alias{}, 275 Default: os.Getenv("PIPER_addonDescriptor"), 276 }, 277 { 278 Name: "maxRuntimeInMinutes", 279 ResourceRef: []config.ResourceReference{}, 280 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 281 Type: "int", 282 Mandatory: true, 283 Aliases: []config.Alias{}, 284 Default: 360, 285 }, 286 { 287 Name: "pollIntervalsInMilliseconds", 288 ResourceRef: []config.ResourceReference{}, 289 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 290 Type: "int", 291 Mandatory: true, 292 Aliases: []config.Alias{}, 293 Default: 60000, 294 }, 295 { 296 Name: "certificateNames", 297 ResourceRef: []config.ResourceReference{}, 298 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 299 Type: "[]string", 300 Mandatory: false, 301 Aliases: []config.Alias{}, 302 Default: []string{}, 303 }, 304 }, 305 }, 306 Containers: []config.Container{ 307 {Name: "cf", Image: "ppiper/cf-cli:7"}, 308 }, 309 Outputs: config.StepOutputs{ 310 Resources: []config.StepResources{ 311 { 312 Name: "commonPipelineEnvironment", 313 Type: "piperEnvironment", 314 Parameters: []map[string]interface{}{ 315 {"name": "abap/addonDescriptor"}, 316 }, 317 }, 318 }, 319 }, 320 }, 321 } 322 return theMetaData 323 }