mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
b81b11ca9d
* Unit Test Assemble Package * Remove obsolete lines dust wiping * climate change * climate change #2 * climate change #3 * climate change #4 * climate change #5 * NSPC serial builds * Actual Delivery Commit * Download Delivery_logs.zip * Publish Result * Testing * !Polling * Provide Commit to BF only if set * dust wiping * More Dust to Wipe * Publish more than on file * Write Log for Publish * fix unit test (now Dummy Entries) * save one line of code for climate change * Update cmd/abapEnvironmentAssemblePackages.go Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * More Detailed Log Messages Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
146 lines
4.6 KiB
Go
146 lines
4.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
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 abapEnvironmentAssembleConfirm(config abapEnvironmentAssembleConfirmOptions, telemetryData *telemetry.CustomData, cpe *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) {
|
|
// for command execution use Command
|
|
c := command.Command{}
|
|
// reroute command output to logging framework
|
|
c.Stdout(log.Writer())
|
|
c.Stderr(log.Writer())
|
|
|
|
var autils = abaputils.AbapUtils{
|
|
Exec: &c,
|
|
}
|
|
|
|
client := piperhttp.Client{}
|
|
err := runAbapEnvironmentAssembleConfirm(&config, telemetryData, &autils, &client, cpe)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
}
|
|
}
|
|
|
|
func runAbapEnvironmentAssembleConfirm(config *abapEnvironmentAssembleConfirmOptions, telemetryData *telemetry.CustomData, com abaputils.Communication, client abapbuild.HTTPSendLoader, cpe *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) error {
|
|
conn := new(abapbuild.Connector)
|
|
var connConfig abapbuild.ConnectorConfiguration
|
|
connConfig.CfAPIEndpoint = config.CfAPIEndpoint
|
|
connConfig.CfOrg = config.CfOrg
|
|
connConfig.CfSpace = config.CfSpace
|
|
connConfig.CfServiceInstance = config.CfServiceInstance
|
|
connConfig.CfServiceKeyName = config.CfServiceKeyName
|
|
connConfig.Host = config.Host
|
|
connConfig.Username = config.Username
|
|
connConfig.Password = config.Password
|
|
connConfig.AddonDescriptor = config.AddonDescriptor
|
|
connConfig.MaxRuntimeInMinutes = config.MaxRuntimeInMinutes
|
|
|
|
err := conn.InitBuildFramework(connConfig, com, client)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var addonDescriptor abaputils.AddonDescriptor
|
|
err = json.Unmarshal([]byte(config.AddonDescriptor), &addonDescriptor)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
delayBetweenPostsInSeconds := time.Duration(3 * time.Second)
|
|
builds, err := startingConfirm(addonDescriptor.Repositories, *conn, delayBetweenPostsInSeconds)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
maxRuntimeInMinutes := time.Duration(config.MaxRuntimeInMinutes) * time.Minute
|
|
pollIntervalsInSeconds := time.Duration(60 * time.Second)
|
|
err = polling(builds, maxRuntimeInMinutes, pollIntervalsInSeconds)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = checkIfFailedAndPrintLogs(builds)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func startingConfirm(repos []abaputils.Repository, conn abapbuild.Connector, delayBetweenPostsInSeconds time.Duration) ([]buildWithRepository, error) {
|
|
var builds []buildWithRepository
|
|
var buildsAlreadyReleased []buildWithRepository
|
|
for _, repo := range repos {
|
|
assemblyBuild := abapbuild.Build{
|
|
Connector: conn,
|
|
}
|
|
buildRepo := buildWithRepository{
|
|
build: assemblyBuild,
|
|
repo: repo,
|
|
}
|
|
if repo.Status != "R" {
|
|
err := buildRepo.startConfirm()
|
|
if err != nil {
|
|
return builds, err
|
|
}
|
|
builds = append(builds, buildRepo)
|
|
} else {
|
|
log.Entry().Infof("Packages %s is in status '%s'. No need assembly done, no need to confirm", repo.PackageName, repo.Status)
|
|
buildsAlreadyReleased = append(buildsAlreadyReleased, buildRepo)
|
|
}
|
|
|
|
//as batch events in the ABAP Backend need a little time
|
|
time.Sleep(delayBetweenPostsInSeconds)
|
|
}
|
|
return builds, nil
|
|
}
|
|
|
|
func polling(builds []buildWithRepository, maxRuntimeInMinutes time.Duration, pollIntervalsInSeconds time.Duration) error {
|
|
timeout := time.After(maxRuntimeInMinutes)
|
|
ticker := time.Tick(pollIntervalsInSeconds)
|
|
for {
|
|
select {
|
|
case <-timeout:
|
|
return errors.New("Timed out")
|
|
case <-ticker:
|
|
var allFinished bool = true
|
|
for i := range builds {
|
|
builds[i].build.Get()
|
|
if !builds[i].build.IsFinished() {
|
|
log.Entry().Infof("Assembly of %s is not yet finished, check again in %s", builds[i].repo.PackageName, pollIntervalsInSeconds)
|
|
allFinished = false
|
|
}
|
|
}
|
|
if allFinished {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *buildWithRepository) startConfirm() error {
|
|
if b.repo.Name == "" || b.repo.Namespace == "" || b.repo.PackageName == "" {
|
|
return errors.New("Parameters missing. Please provide software component name, namespace and packagename")
|
|
}
|
|
valuesInput := abapbuild.Values{
|
|
Values: []abapbuild.Value{
|
|
{
|
|
ValueID: "SWC",
|
|
Value: b.repo.Name,
|
|
},
|
|
{
|
|
ValueID: "SSDC-delta",
|
|
Value: b.repo.Namespace + b.repo.PackageName,
|
|
},
|
|
},
|
|
}
|
|
phase := "BUILD_CONFIRM"
|
|
log.Entry().Infof("Starting confirmation of package %s", b.repo.PackageName)
|
|
return b.build.Start(phase, valuesInput)
|
|
}
|