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