github.com/jaylevin/jenkins-library@v1.230.4/cmd/transportRequestUploadCTS_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 transportRequestUploadCTSOptions struct { 21 Description string `json:"description,omitempty"` 22 Endpoint string `json:"endpoint,omitempty"` 23 Client string `json:"client,omitempty"` 24 Username string `json:"username,omitempty"` 25 Password string `json:"password,omitempty"` 26 ApplicationName string `json:"applicationName,omitempty"` 27 AbapPackage string `json:"abapPackage,omitempty"` 28 OsDeployUser string `json:"osDeployUser,omitempty"` 29 DeployConfigFile string `json:"deployConfigFile,omitempty"` 30 TransportRequestID string `json:"transportRequestId,omitempty"` 31 DeployToolDependencies []string `json:"deployToolDependencies,omitempty"` 32 NpmInstallOpts []string `json:"npmInstallOpts,omitempty"` 33 } 34 35 type transportRequestUploadCTSCommonPipelineEnvironment struct { 36 custom struct { 37 transportRequestID string 38 } 39 } 40 41 func (p *transportRequestUploadCTSCommonPipelineEnvironment) persist(path, resourceName string) { 42 content := []struct { 43 category string 44 name string 45 value interface{} 46 }{ 47 {category: "custom", name: "transportRequestId", value: p.custom.transportRequestID}, 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 // TransportRequestUploadCTSCommand This step uploads an UI5 application to the SAPUI5 ABAP repository. 64 func TransportRequestUploadCTSCommand() *cobra.Command { 65 const STEP_NAME = "transportRequestUploadCTS" 66 67 metadata := transportRequestUploadCTSMetadata() 68 var stepConfig transportRequestUploadCTSOptions 69 var startTime time.Time 70 var commonPipelineEnvironment transportRequestUploadCTSCommonPipelineEnvironment 71 var logCollector *log.CollectorHook 72 var splunkClient *splunk.Splunk 73 telemetryClient := &telemetry.Telemetry{} 74 75 var createTransportRequestUploadCTSCmd = &cobra.Command{ 76 Use: STEP_NAME, 77 Short: "This step uploads an UI5 application to the SAPUI5 ABAP repository.", 78 Long: `This step uploads an UI5 application from your project folder to the SAPUI5 ABAP repository of the SAPUI5 ABAP back-end infrastructure using the SAPUI5 Repository OData service. 79 It processes the results of the ` + "`" + `ui5 build` + "`" + ` command of the SAPUI5 toolset.`, 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 transportRequestUploadCTS(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 147 stepTelemetryData.ErrorCode = "0" 148 log.Entry().Info("SUCCESS") 149 }, 150 } 151 152 addTransportRequestUploadCTSFlags(createTransportRequestUploadCTSCmd, &stepConfig) 153 return createTransportRequestUploadCTSCmd 154 } 155 156 func addTransportRequestUploadCTSFlags(cmd *cobra.Command, stepConfig *transportRequestUploadCTSOptions) { 157 cmd.Flags().StringVar(&stepConfig.Description, "description", `Deployed with Piper based on SAP Fiori tools`, "The description of the application. The description is only taken into account for a new upload. In case of an update the description will not be updated.") 158 cmd.Flags().StringVar(&stepConfig.Endpoint, "endpoint", os.Getenv("PIPER_endpoint"), "The ODATA service endpoint: https://<host>:<port>") 159 cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "The ABAP client") 160 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "Service user for uploading to the SAPUI5 ABAP repository") 161 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Service user password for uploading to the SAPUI5 ABAP repository") 162 cmd.Flags().StringVar(&stepConfig.ApplicationName, "applicationName", os.Getenv("PIPER_applicationName"), "Name of the UI5 application") 163 cmd.Flags().StringVar(&stepConfig.AbapPackage, "abapPackage", os.Getenv("PIPER_abapPackage"), "ABAP package name of the UI5 application") 164 cmd.Flags().StringVar(&stepConfig.OsDeployUser, "osDeployUser", `node`, "Docker image user performing the deployment") 165 cmd.Flags().StringVar(&stepConfig.DeployConfigFile, "deployConfigFile", `ui5-deploy.yaml`, "Configuration file for the fiori deployment") 166 cmd.Flags().StringVar(&stepConfig.TransportRequestID, "transportRequestId", os.Getenv("PIPER_transportRequestId"), "ID of the transport request to which the UI5 application is uploaded") 167 cmd.Flags().StringSliceVar(&stepConfig.DeployToolDependencies, "deployToolDependencies", []string{`@ui5/cli`, `@sap/ux-ui5-tooling`, `@ui5/logger`, `@ui5/fs`}, "List of additional dependencies to fiori related packages. By default a standard node docker image is used on which the dependencies are installed. Provide an empty list, in case your docker image already contains the required dependencies") 168 cmd.Flags().StringSliceVar(&stepConfig.NpmInstallOpts, "npmInstallOpts", []string{}, "List of additional installation options for the npm install call. `-g`, `--global` is always assumed. Can be used for e.g. providing custom registries (`--registry https://your.registry.com`) or for providing the verbose flag (`--verbose`) for troubleshooting") 169 170 cmd.MarkFlagRequired("username") 171 cmd.MarkFlagRequired("password") 172 cmd.MarkFlagRequired("applicationName") 173 cmd.MarkFlagRequired("abapPackage") 174 cmd.MarkFlagRequired("transportRequestId") 175 } 176 177 // retrieve step metadata 178 func transportRequestUploadCTSMetadata() config.StepData { 179 var theMetaData = config.StepData{ 180 Metadata: config.StepMetadata{ 181 Name: "transportRequestUploadCTS", 182 Aliases: []config.Alias{{Name: "transportRequestUploadFile", Deprecated: false}}, 183 Description: "This step uploads an UI5 application to the SAPUI5 ABAP repository.", 184 }, 185 Spec: config.StepSpec{ 186 Inputs: config.StepInputs{ 187 Secrets: []config.StepSecrets{ 188 {Name: "uploadCredentialsId", Description: "Jenkins 'Username with password' credentials ID containing user and password to authenticate against the ABAP system.", Type: "jenkins", Aliases: []config.Alias{{Name: "changeManagement/credentialsId", Deprecated: false}}}, 189 }, 190 Parameters: []config.StepParameters{ 191 { 192 Name: "description", 193 ResourceRef: []config.ResourceReference{}, 194 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 195 Type: "string", 196 Mandatory: false, 197 Aliases: []config.Alias{{Name: "applicationDescription"}}, 198 Default: `Deployed with Piper based on SAP Fiori tools`, 199 }, 200 { 201 Name: "endpoint", 202 ResourceRef: []config.ResourceReference{}, 203 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 204 Type: "string", 205 Mandatory: false, 206 Aliases: []config.Alias{{Name: "changeManagement/endpoint"}, {Name: "changeManagement/cts/endpoint"}}, 207 Default: os.Getenv("PIPER_endpoint"), 208 }, 209 { 210 Name: "client", 211 ResourceRef: []config.ResourceReference{}, 212 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 213 Type: "string", 214 Mandatory: false, 215 Aliases: []config.Alias{{Name: "changeManagement/client"}, {Name: "changeManagement/cts/client"}}, 216 Default: os.Getenv("PIPER_client"), 217 }, 218 { 219 Name: "username", 220 ResourceRef: []config.ResourceReference{}, 221 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 222 Type: "string", 223 Mandatory: true, 224 Aliases: []config.Alias{}, 225 Default: os.Getenv("PIPER_username"), 226 }, 227 { 228 Name: "password", 229 ResourceRef: []config.ResourceReference{}, 230 Scope: []string{"PARAMETERS"}, 231 Type: "string", 232 Mandatory: true, 233 Aliases: []config.Alias{}, 234 Default: os.Getenv("PIPER_password"), 235 }, 236 { 237 Name: "applicationName", 238 ResourceRef: []config.ResourceReference{}, 239 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 240 Type: "string", 241 Mandatory: true, 242 Aliases: []config.Alias{}, 243 Default: os.Getenv("PIPER_applicationName"), 244 }, 245 { 246 Name: "abapPackage", 247 ResourceRef: []config.ResourceReference{}, 248 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 249 Type: "string", 250 Mandatory: true, 251 Aliases: []config.Alias{}, 252 Default: os.Getenv("PIPER_abapPackage"), 253 }, 254 { 255 Name: "osDeployUser", 256 ResourceRef: []config.ResourceReference{}, 257 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 258 Type: "string", 259 Mandatory: false, 260 Aliases: []config.Alias{{Name: "changeManagement/osDeployUser"}, {Name: "changeManagement/cts/osDeployUser"}}, 261 Default: `node`, 262 }, 263 { 264 Name: "deployConfigFile", 265 ResourceRef: []config.ResourceReference{}, 266 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 267 Type: "string", 268 Mandatory: false, 269 Aliases: []config.Alias{{Name: "changeManagement/deployConfigFile"}, {Name: "changeManagement/cts/deployConfigFile"}}, 270 Default: `ui5-deploy.yaml`, 271 }, 272 { 273 Name: "transportRequestId", 274 ResourceRef: []config.ResourceReference{ 275 { 276 Name: "commonPipelineEnvironment", 277 Param: "custom/transportRequestId", 278 }, 279 }, 280 Scope: []string{"PARAMETERS"}, 281 Type: "string", 282 Mandatory: true, 283 Aliases: []config.Alias{}, 284 Default: os.Getenv("PIPER_transportRequestId"), 285 }, 286 { 287 Name: "deployToolDependencies", 288 ResourceRef: []config.ResourceReference{}, 289 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 290 Type: "[]string", 291 Mandatory: false, 292 Aliases: []config.Alias{{Name: "changeManagement/deployToolDependencies"}, {Name: "changeManagement/cts/deployToolDependencies"}}, 293 Default: []string{`@ui5/cli`, `@sap/ux-ui5-tooling`, `@ui5/logger`, `@ui5/fs`}, 294 }, 295 { 296 Name: "npmInstallOpts", 297 ResourceRef: []config.ResourceReference{}, 298 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 299 Type: "[]string", 300 Mandatory: false, 301 Aliases: []config.Alias{{Name: "changeManagement/npmInstallOpts"}, {Name: "changeManagement/cts/npmInstallOpts"}}, 302 Default: []string{}, 303 }, 304 }, 305 }, 306 Containers: []config.Container{ 307 {Name: "fiori-client", Image: "node"}, 308 }, 309 Outputs: config.StepOutputs{ 310 Resources: []config.StepResources{ 311 { 312 Name: "commonPipelineEnvironment", 313 Type: "piperEnvironment", 314 Parameters: []map[string]interface{}{ 315 {"name": "custom/transportRequestId"}, 316 }, 317 }, 318 }, 319 }, 320 }, 321 } 322 return theMetaData 323 }