mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
* new checks for commitIDs * new checks for commitIDs * relocate step from build stage to initial checks + refac * log list * fix log + check * log format * fix unit tests * targetVector refac + polling * refac * refac 2 * polling * remove debug output * remove debug output Co-authored-by: Christian Luttenberger <42861202+bluesbrother84@users.noreply.github.com>
74 lines
3.0 KiB
Go
74 lines
3.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/abap/aakaas"
|
|
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
|
|
"github.com/SAP/jenkins-library/pkg/abaputils"
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func abapAddonAssemblyKitPublishTargetVector(config abapAddonAssemblyKitPublishTargetVectorOptions, telemetryData *telemetry.CustomData) {
|
|
// for command execution use Command
|
|
c := command.Command{}
|
|
// reroute command output to logging framework
|
|
c.Stdout(log.Writer())
|
|
c.Stderr(log.Writer())
|
|
|
|
client := piperhttp.Client{}
|
|
|
|
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
|
|
err := runAbapAddonAssemblyKitPublishTargetVector(&config, telemetryData, &client, time.Duration(config.MaxRuntimeInMinutes)*time.Minute, time.Duration(config.PollingIntervalInSeconds)*time.Second)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
}
|
|
}
|
|
|
|
func runAbapAddonAssemblyKitPublishTargetVector(config *abapAddonAssemblyKitPublishTargetVectorOptions, telemetryData *telemetry.CustomData, client piperhttp.Sender,
|
|
maxRuntime time.Duration, pollingInterval time.Duration) error {
|
|
|
|
conn := new(abapbuild.Connector)
|
|
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client); err != nil {
|
|
return err
|
|
}
|
|
conn.MaxRuntime = maxRuntime
|
|
conn.PollingInterval = pollingInterval
|
|
|
|
addonDescriptor := new(abaputils.AddonDescriptor)
|
|
if err := addonDescriptor.InitFromJSONstring(config.AddonDescriptor); err != nil {
|
|
return errors.Wrap(err, "Reading AddonDescriptor failed [Make sure abapAddonAssemblyKit...CheckCVs|CheckPV steps have been run before]")
|
|
}
|
|
|
|
if addonDescriptor.TargetVectorID == "" {
|
|
return errors.New("Parameter missing. Please provide the target vector id (e.g. by running step abapAddonAssemblyKitCreateTargetVector beforehand")
|
|
}
|
|
targetVector := new(aakaas.TargetVector)
|
|
targetVector.InitExisting(addonDescriptor.TargetVectorID)
|
|
|
|
switch config.TargetVectorScope {
|
|
case string(aakaas.TargetVectorStatusTest):
|
|
log.Entry().Infof("Publish target vector %s for test use", addonDescriptor.TargetVectorID)
|
|
case string(aakaas.TargetVectorStatusProductive):
|
|
log.Entry().Infof("Publish target vector %s for productive use", addonDescriptor.TargetVectorID)
|
|
default:
|
|
return errors.New("Invalid Value of configuration Parameter TargetVectorScope: " + config.TargetVectorScope)
|
|
}
|
|
|
|
if err := targetVector.PublishTargetVector(conn, aakaas.TargetVectorStatus(config.TargetVectorScope)); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Entry().Info("Waiting for target vector publishing to finish")
|
|
if err := targetVector.PollForStatus(conn, aakaas.TargetVectorStatus(config.TargetVectorScope)); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Entry().Info("Success: Publishing finised")
|
|
return nil
|
|
}
|