github.com/jaylevin/jenkins-library@v1.230.4/cmd/abapEnvironmentCreateTag_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 "time" 9 10 "github.com/SAP/jenkins-library/pkg/config" 11 "github.com/SAP/jenkins-library/pkg/log" 12 "github.com/SAP/jenkins-library/pkg/splunk" 13 "github.com/SAP/jenkins-library/pkg/telemetry" 14 "github.com/SAP/jenkins-library/pkg/validation" 15 "github.com/spf13/cobra" 16 ) 17 18 type abapEnvironmentCreateTagOptions struct { 19 Username string `json:"username,omitempty"` 20 Password string `json:"password,omitempty"` 21 Repositories string `json:"repositories,omitempty"` 22 RepositoryName string `json:"repositoryName,omitempty"` 23 CommitID string `json:"commitID,omitempty"` 24 TagName string `json:"tagName,omitempty"` 25 TagDescription string `json:"tagDescription,omitempty"` 26 GenerateTagForAddonProductVersion bool `json:"generateTagForAddonProductVersion,omitempty"` 27 GenerateTagForAddonComponentVersion bool `json:"generateTagForAddonComponentVersion,omitempty"` 28 Host string `json:"host,omitempty"` 29 CfAPIEndpoint string `json:"cfApiEndpoint,omitempty"` 30 CfOrg string `json:"cfOrg,omitempty"` 31 CfSpace string `json:"cfSpace,omitempty"` 32 CfServiceInstance string `json:"cfServiceInstance,omitempty"` 33 CfServiceKeyName string `json:"cfServiceKeyName,omitempty"` 34 } 35 36 // AbapEnvironmentCreateTagCommand Creates a tag for a git repository to a SAP BTP ABAP Environment system 37 func AbapEnvironmentCreateTagCommand() *cobra.Command { 38 const STEP_NAME = "abapEnvironmentCreateTag" 39 40 metadata := abapEnvironmentCreateTagMetadata() 41 var stepConfig abapEnvironmentCreateTagOptions 42 var startTime time.Time 43 var logCollector *log.CollectorHook 44 var splunkClient *splunk.Splunk 45 telemetryClient := &telemetry.Telemetry{} 46 47 var createAbapEnvironmentCreateTagCmd = &cobra.Command{ 48 Use: STEP_NAME, 49 Short: "Creates a tag for a git repository to a SAP BTP ABAP Environment system", 50 Long: `Creates tags for specific commits of one or multiple repositories / software components. The tag can be specified explicitly as well as being generated by an addon product version or an addon component version. 51 Please provide either of the following options: 52 53 * The host and credentials the BTP ABAP Environment system itself. The credentials must be configured for the Communication Scenario [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html). 54 * The Cloud Foundry parameters (API endpoint, organization, space), credentials, the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510. 55 * Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.`, 56 PreRunE: func(cmd *cobra.Command, _ []string) error { 57 startTime = time.Now() 58 log.SetStepName(STEP_NAME) 59 log.SetVerbose(GeneralConfig.Verbose) 60 61 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 62 63 path, _ := os.Getwd() 64 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 65 log.RegisterHook(fatalHook) 66 67 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 68 if err != nil { 69 log.SetErrorCategory(log.ErrorConfiguration) 70 return err 71 } 72 log.RegisterSecret(stepConfig.Username) 73 log.RegisterSecret(stepConfig.Password) 74 75 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 76 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 77 log.RegisterHook(&sentryHook) 78 } 79 80 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 81 splunkClient = &splunk.Splunk{} 82 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 83 log.RegisterHook(logCollector) 84 } 85 86 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 87 if err != nil { 88 return err 89 } 90 if err = validation.ValidateStruct(stepConfig); err != nil { 91 log.SetErrorCategory(log.ErrorConfiguration) 92 return err 93 } 94 95 return nil 96 }, 97 Run: func(_ *cobra.Command, _ []string) { 98 stepTelemetryData := telemetry.CustomData{} 99 stepTelemetryData.ErrorCode = "1" 100 handler := func() { 101 config.RemoveVaultSecretFiles() 102 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 103 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 104 stepTelemetryData.PiperCommitHash = GitCommit 105 telemetryClient.SetData(&stepTelemetryData) 106 telemetryClient.Send() 107 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 108 splunkClient.Send(telemetryClient.GetData(), logCollector) 109 } 110 } 111 log.DeferExitHandler(handler) 112 defer handler() 113 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 114 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 115 splunkClient.Initialize(GeneralConfig.CorrelationID, 116 GeneralConfig.HookConfig.SplunkConfig.Dsn, 117 GeneralConfig.HookConfig.SplunkConfig.Token, 118 GeneralConfig.HookConfig.SplunkConfig.Index, 119 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 120 } 121 abapEnvironmentCreateTag(stepConfig, &stepTelemetryData) 122 stepTelemetryData.ErrorCode = "0" 123 log.Entry().Info("SUCCESS") 124 }, 125 } 126 127 addAbapEnvironmentCreateTagFlags(createAbapEnvironmentCreateTagCmd, &stepConfig) 128 return createAbapEnvironmentCreateTagCmd 129 } 130 131 func addAbapEnvironmentCreateTagFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCreateTagOptions) { 132 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") 133 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510") 134 cmd.Flags().StringVar(&stepConfig.Repositories, "repositories", os.Getenv("PIPER_repositories"), "Specifies a YAML file containing the repositories configuration") 135 cmd.Flags().StringVar(&stepConfig.RepositoryName, "repositoryName", os.Getenv("PIPER_repositoryName"), "Specifies a repository (Software Components) on the SAP BTP ABAP Environment system") 136 cmd.Flags().StringVar(&stepConfig.CommitID, "commitID", os.Getenv("PIPER_commitID"), "Specifies a commitID, for which a tag will be created") 137 cmd.Flags().StringVar(&stepConfig.TagName, "tagName", os.Getenv("PIPER_tagName"), "Specifies a tagName that will be created for the repositories on the SAP BTP ABAP Environment system") 138 cmd.Flags().StringVar(&stepConfig.TagDescription, "tagDescription", os.Getenv("PIPER_tagDescription"), "Specifies a description for the created tag") 139 cmd.Flags().BoolVar(&stepConfig.GenerateTagForAddonProductVersion, "generateTagForAddonProductVersion", false, "Specifies if a tag will be created for the repositories on the SAP BTP ABAP Environment system") 140 cmd.Flags().BoolVar(&stepConfig.GenerateTagForAddonComponentVersion, "generateTagForAddonComponentVersion", false, "Specifies if a tag will be created for the repositories on the SAP BTP ABAP Environment system") 141 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP BTP ABAP Environment system") 142 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", os.Getenv("PIPER_cfApiEndpoint"), "Cloud Foundry API Enpoint") 143 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry target organization") 144 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry target space") 145 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Cloud Foundry Service Instance") 146 cmd.Flags().StringVar(&stepConfig.CfServiceKeyName, "cfServiceKeyName", os.Getenv("PIPER_cfServiceKeyName"), "Cloud Foundry Service Key") 147 148 cmd.MarkFlagRequired("username") 149 cmd.MarkFlagRequired("password") 150 } 151 152 // retrieve step metadata 153 func abapEnvironmentCreateTagMetadata() config.StepData { 154 var theMetaData = config.StepData{ 155 Metadata: config.StepMetadata{ 156 Name: "abapEnvironmentCreateTag", 157 Aliases: []config.Alias{}, 158 Description: "Creates a tag for a git repository to a SAP BTP ABAP Environment system", 159 }, 160 Spec: config.StepSpec{ 161 Inputs: config.StepInputs{ 162 Secrets: []config.StepSecrets{ 163 {Name: "abapCredentialsId", Description: "Jenkins credentials ID containing user and password to authenticate to the BTP ABAP Environment system or the Cloud Foundry API", Type: "jenkins", Aliases: []config.Alias{{Name: "cfCredentialsId", Deprecated: false}, {Name: "credentialsId", Deprecated: false}}}, 164 }, 165 Parameters: []config.StepParameters{ 166 { 167 Name: "username", 168 ResourceRef: []config.ResourceReference{ 169 { 170 Name: "abapCredentialsId", 171 Param: "username", 172 Type: "secret", 173 }, 174 }, 175 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 176 Type: "string", 177 Mandatory: true, 178 Aliases: []config.Alias{}, 179 Default: os.Getenv("PIPER_username"), 180 }, 181 { 182 Name: "password", 183 ResourceRef: []config.ResourceReference{ 184 { 185 Name: "abapCredentialsId", 186 Param: "password", 187 Type: "secret", 188 }, 189 }, 190 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 191 Type: "string", 192 Mandatory: true, 193 Aliases: []config.Alias{}, 194 Default: os.Getenv("PIPER_password"), 195 }, 196 { 197 Name: "repositories", 198 ResourceRef: []config.ResourceReference{}, 199 Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"}, 200 Type: "string", 201 Mandatory: false, 202 Aliases: []config.Alias{}, 203 Default: os.Getenv("PIPER_repositories"), 204 }, 205 { 206 Name: "repositoryName", 207 ResourceRef: []config.ResourceReference{}, 208 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 209 Type: "string", 210 Mandatory: false, 211 Aliases: []config.Alias{}, 212 Default: os.Getenv("PIPER_repositoryName"), 213 }, 214 { 215 Name: "commitID", 216 ResourceRef: []config.ResourceReference{}, 217 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 218 Type: "string", 219 Mandatory: false, 220 Aliases: []config.Alias{}, 221 Default: os.Getenv("PIPER_commitID"), 222 }, 223 { 224 Name: "tagName", 225 ResourceRef: []config.ResourceReference{}, 226 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 227 Type: "string", 228 Mandatory: false, 229 Aliases: []config.Alias{}, 230 Default: os.Getenv("PIPER_tagName"), 231 }, 232 { 233 Name: "tagDescription", 234 ResourceRef: []config.ResourceReference{}, 235 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 236 Type: "string", 237 Mandatory: false, 238 Aliases: []config.Alias{}, 239 Default: os.Getenv("PIPER_tagDescription"), 240 }, 241 { 242 Name: "generateTagForAddonProductVersion", 243 ResourceRef: []config.ResourceReference{}, 244 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 245 Type: "bool", 246 Mandatory: false, 247 Aliases: []config.Alias{}, 248 Default: false, 249 }, 250 { 251 Name: "generateTagForAddonComponentVersion", 252 ResourceRef: []config.ResourceReference{}, 253 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 254 Type: "bool", 255 Mandatory: false, 256 Aliases: []config.Alias{}, 257 Default: false, 258 }, 259 { 260 Name: "host", 261 ResourceRef: []config.ResourceReference{}, 262 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 263 Type: "string", 264 Mandatory: false, 265 Aliases: []config.Alias{}, 266 Default: os.Getenv("PIPER_host"), 267 }, 268 { 269 Name: "cfApiEndpoint", 270 ResourceRef: []config.ResourceReference{}, 271 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 272 Type: "string", 273 Mandatory: false, 274 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 275 Default: os.Getenv("PIPER_cfApiEndpoint"), 276 }, 277 { 278 Name: "cfOrg", 279 ResourceRef: []config.ResourceReference{}, 280 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 281 Type: "string", 282 Mandatory: false, 283 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 284 Default: os.Getenv("PIPER_cfOrg"), 285 }, 286 { 287 Name: "cfSpace", 288 ResourceRef: []config.ResourceReference{}, 289 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 290 Type: "string", 291 Mandatory: false, 292 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 293 Default: os.Getenv("PIPER_cfSpace"), 294 }, 295 { 296 Name: "cfServiceInstance", 297 ResourceRef: []config.ResourceReference{}, 298 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 299 Type: "string", 300 Mandatory: false, 301 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 302 Default: os.Getenv("PIPER_cfServiceInstance"), 303 }, 304 { 305 Name: "cfServiceKeyName", 306 ResourceRef: []config.ResourceReference{}, 307 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 308 Type: "string", 309 Mandatory: false, 310 Aliases: []config.Alias{{Name: "cloudFoundry/serviceKey"}, {Name: "cloudFoundry/serviceKeyName"}, {Name: "cfServiceKey"}}, 311 Default: os.Getenv("PIPER_cfServiceKeyName"), 312 }, 313 }, 314 }, 315 Containers: []config.Container{ 316 {Name: "cf", Image: "ppiper/cf-cli:7"}, 317 }, 318 }, 319 } 320 return theMetaData 321 }