mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
196 lines
7.2 KiB
Go
196 lines
7.2 KiB
Go
|
// Code generated by piper's step-generator. DO NOT EDIT.
|
||
|
|
||
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"github.com/SAP/jenkins-library/pkg/config"
|
||
|
"github.com/SAP/jenkins-library/pkg/log"
|
||
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
type transportRequestUploadSOLMANOptions struct {
|
||
|
Endpoint string `json:"endpoint,omitempty"`
|
||
|
Username string `json:"username,omitempty"`
|
||
|
Password string `json:"password,omitempty"`
|
||
|
ApplicationID string `json:"applicationId,omitempty"`
|
||
|
ChangeDocumentID string `json:"changeDocumentId,omitempty"`
|
||
|
TransportRequestID string `json:"transportRequestId,omitempty"`
|
||
|
FilePath string `json:"filePath,omitempty"`
|
||
|
CmClientOpts []string `json:"cmClientOpts,omitempty"`
|
||
|
}
|
||
|
|
||
|
// TransportRequestUploadSOLMANCommand Uploads content to a transport request
|
||
|
func TransportRequestUploadSOLMANCommand() *cobra.Command {
|
||
|
const STEP_NAME = "transportRequestUploadSOLMAN"
|
||
|
|
||
|
metadata := transportRequestUploadSOLMANMetadata()
|
||
|
var stepConfig transportRequestUploadSOLMANOptions
|
||
|
var startTime time.Time
|
||
|
|
||
|
var createTransportRequestUploadSOLMANCmd = &cobra.Command{
|
||
|
Use: STEP_NAME,
|
||
|
Short: "Uploads content to a transport request",
|
||
|
Long: `Uploads content to a transport request which is associated with a change document in SAP Solution Manager`,
|
||
|
PreRunE: func(cmd *cobra.Command, _ []string) error {
|
||
|
startTime = time.Now()
|
||
|
log.SetStepName(STEP_NAME)
|
||
|
log.SetVerbose(GeneralConfig.Verbose)
|
||
|
|
||
|
path, _ := os.Getwd()
|
||
|
fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path}
|
||
|
log.RegisterHook(fatalHook)
|
||
|
|
||
|
err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile)
|
||
|
if err != nil {
|
||
|
log.SetErrorCategory(log.ErrorConfiguration)
|
||
|
return err
|
||
|
}
|
||
|
log.RegisterSecret(stepConfig.Username)
|
||
|
log.RegisterSecret(stepConfig.Password)
|
||
|
|
||
|
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
|
||
|
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
|
||
|
log.RegisterHook(&sentryHook)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
},
|
||
|
Run: func(_ *cobra.Command, _ []string) {
|
||
|
telemetryData := telemetry.CustomData{}
|
||
|
telemetryData.ErrorCode = "1"
|
||
|
handler := func() {
|
||
|
config.RemoveVaultSecretFiles()
|
||
|
telemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds())
|
||
|
telemetryData.ErrorCategory = log.GetErrorCategory().String()
|
||
|
telemetry.Send(&telemetryData)
|
||
|
}
|
||
|
log.DeferExitHandler(handler)
|
||
|
defer handler()
|
||
|
telemetry.Initialize(GeneralConfig.NoTelemetry, STEP_NAME)
|
||
|
transportRequestUploadSOLMAN(stepConfig, &telemetryData)
|
||
|
telemetryData.ErrorCode = "0"
|
||
|
log.Entry().Info("SUCCESS")
|
||
|
},
|
||
|
}
|
||
|
|
||
|
addTransportRequestUploadSOLMANFlags(createTransportRequestUploadSOLMANCmd, &stepConfig)
|
||
|
return createTransportRequestUploadSOLMANCmd
|
||
|
}
|
||
|
|
||
|
func addTransportRequestUploadSOLMANFlags(cmd *cobra.Command, stepConfig *transportRequestUploadSOLMANOptions) {
|
||
|
cmd.Flags().StringVar(&stepConfig.Endpoint, "endpoint", os.Getenv("PIPER_endpoint"), "Service endpoint")
|
||
|
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "Operating system user for triggering the deployment")
|
||
|
cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the deploy user")
|
||
|
cmd.Flags().StringVar(&stepConfig.ApplicationID, "applicationId", os.Getenv("PIPER_applicationId"), "Id of the application.")
|
||
|
cmd.Flags().StringVar(&stepConfig.ChangeDocumentID, "changeDocumentId", os.Getenv("PIPER_changeDocumentId"), "Id of the change document to upload the file. This parameter is only taken into account when provided via signature to the step.")
|
||
|
cmd.Flags().StringVar(&stepConfig.TransportRequestID, "transportRequestId", os.Getenv("PIPER_transportRequestId"), "Id of the transport request to upload the file. This parameter is only taken into account when provided via signature to the step.")
|
||
|
cmd.Flags().StringVar(&stepConfig.FilePath, "filePath", os.Getenv("PIPER_filePath"), "Name/Path of the file which should be uploaded")
|
||
|
cmd.Flags().StringSliceVar(&stepConfig.CmClientOpts, "cmClientOpts", []string{}, "Additional options handed over to the cm client")
|
||
|
|
||
|
cmd.MarkFlagRequired("endpoint")
|
||
|
cmd.MarkFlagRequired("username")
|
||
|
cmd.MarkFlagRequired("password")
|
||
|
cmd.MarkFlagRequired("applicationId")
|
||
|
cmd.MarkFlagRequired("changeDocumentId")
|
||
|
cmd.MarkFlagRequired("transportRequestId")
|
||
|
cmd.MarkFlagRequired("filePath")
|
||
|
cmd.MarkFlagRequired("cmClientOpts")
|
||
|
}
|
||
|
|
||
|
// retrieve step metadata
|
||
|
func transportRequestUploadSOLMANMetadata() config.StepData {
|
||
|
var theMetaData = config.StepData{
|
||
|
Metadata: config.StepMetadata{
|
||
|
Name: "transportRequestUploadSOLMAN",
|
||
|
Aliases: []config.Alias{{Name: "transportRequestUploadFile", Deprecated: false}},
|
||
|
Description: "Uploads content to a transport request",
|
||
|
},
|
||
|
Spec: config.StepSpec{
|
||
|
Inputs: config.StepInputs{
|
||
|
Parameters: []config.StepParameters{
|
||
|
{
|
||
|
Name: "endpoint",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{{Name: "changeManagement/endpoint"}},
|
||
|
},
|
||
|
{
|
||
|
Name: "username",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "password",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "applicationId",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "changeDocumentId",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "transportRequestId",
|
||
|
ResourceRef: []config.ResourceReference{
|
||
|
{
|
||
|
Name: "commonPipelineEnvironment",
|
||
|
Param: "custom/transportRequestId",
|
||
|
},
|
||
|
},
|
||
|
Scope: []string{"PARAMETERS"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "filePath",
|
||
|
ResourceRef: []config.ResourceReference{
|
||
|
{
|
||
|
Name: "commonPipelineEnvironment",
|
||
|
Param: "mtarFilePath",
|
||
|
},
|
||
|
},
|
||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||
|
Type: "string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{},
|
||
|
},
|
||
|
{
|
||
|
Name: "cmClientOpts",
|
||
|
ResourceRef: []config.ResourceReference{},
|
||
|
Scope: []string{"PARAMETERS", "STAGES", "STEP", "GENERAL"},
|
||
|
Type: "[]string",
|
||
|
Mandatory: true,
|
||
|
Aliases: []config.Alias{{Name: "clientOpts"}, {Name: "changeManagement/clientOpts"}},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
return theMetaData
|
||
|
}
|