You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
RobustConfirm (#3179)
confirm no longer done based on package status but now based on boolean indicator which is set during assembly step. Thus confirm can now be placed after release packages.
This commit is contained in:
@@ -54,14 +54,14 @@ func runAbapEnvironmentAssembleConfirm(config *abapEnvironmentAssembleConfirmOpt
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
delayBetweenPostsInSeconds := time.Duration(3 * time.Second)
|
||||
builds, err := startingConfirm(addonDescriptor.Repositories, *conn, delayBetweenPostsInSeconds)
|
||||
delayBetweenPosts := time.Duration(3 * time.Second)
|
||||
builds, err := startingConfirm(addonDescriptor.Repositories, *conn, delayBetweenPosts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
maxRuntimeInMinutes := time.Duration(config.MaxRuntimeInMinutes) * time.Minute
|
||||
pollIntervalsInSeconds := time.Duration(60 * time.Second)
|
||||
err = polling(builds, maxRuntimeInMinutes, pollIntervalsInSeconds)
|
||||
pollInterval := time.Duration(60 * time.Second)
|
||||
err = polling(builds, maxRuntimeInMinutes, pollInterval)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -72,9 +72,8 @@ func runAbapEnvironmentAssembleConfirm(config *abapEnvironmentAssembleConfirmOpt
|
||||
return nil
|
||||
}
|
||||
|
||||
func startingConfirm(repos []abaputils.Repository, conn abapbuild.Connector, delayBetweenPostsInSeconds time.Duration) ([]buildWithRepository, error) {
|
||||
var builds []buildWithRepository
|
||||
var buildsAlreadyReleased []buildWithRepository
|
||||
func startingConfirm(repos []abaputils.Repository, conn abapbuild.Connector, delayBetweenPosts time.Duration) ([]buildWithRepository, error) {
|
||||
var confirmedBuilds []buildWithRepository
|
||||
for _, repo := range repos {
|
||||
assemblyBuild := abapbuild.Build{
|
||||
Connector: conn,
|
||||
@@ -83,26 +82,25 @@ func startingConfirm(repos []abaputils.Repository, conn abapbuild.Connector, del
|
||||
build: assemblyBuild,
|
||||
repo: repo,
|
||||
}
|
||||
if repo.Status != "R" {
|
||||
if repo.InBuildScope {
|
||||
err := buildRepo.startConfirm()
|
||||
if err != nil {
|
||||
return builds, err
|
||||
return confirmedBuilds, err
|
||||
}
|
||||
builds = append(builds, buildRepo)
|
||||
confirmedBuilds = append(confirmedBuilds, 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)
|
||||
log.Entry().Infof("Packages %s was not assembled in this pipeline run, thus no need to confirm", repo.PackageName)
|
||||
}
|
||||
|
||||
//as batch events in the ABAP Backend need a little time
|
||||
time.Sleep(delayBetweenPostsInSeconds)
|
||||
time.Sleep(delayBetweenPosts)
|
||||
}
|
||||
return builds, nil
|
||||
return confirmedBuilds, nil
|
||||
}
|
||||
|
||||
func polling(builds []buildWithRepository, maxRuntimeInMinutes time.Duration, pollIntervalsInSeconds time.Duration) error {
|
||||
func polling(builds []buildWithRepository, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) error {
|
||||
timeout := time.After(maxRuntimeInMinutes)
|
||||
ticker := time.Tick(pollIntervalsInSeconds)
|
||||
ticker := time.Tick(pollInterval)
|
||||
for {
|
||||
select {
|
||||
case <-timeout:
|
||||
@@ -112,7 +110,7 @@ func polling(builds []buildWithRepository, maxRuntimeInMinutes time.Duration, po
|
||||
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)
|
||||
log.Entry().Infof("Assembly of %s is not yet finished, check again in %s", builds[i].repo.PackageName, pollInterval)
|
||||
allFinished = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ func TestStartingConfirm(t *testing.T) {
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
repo.Status = "R"
|
||||
repo.InBuildScope = true
|
||||
repos = append(repos, repo)
|
||||
|
||||
builds, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
|
||||
@@ -66,8 +67,8 @@ func TestStartingConfirmInvalidInput(t *testing.T) {
|
||||
conn.Header = make(map[string][]string)
|
||||
var repos []abaputils.Repository
|
||||
repo := abaputils.Repository{
|
||||
Name: "RepoA",
|
||||
Status: "P",
|
||||
Name: "RepoA",
|
||||
InBuildScope: true,
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
_, err := startingConfirm(repos, *conn, time.Duration(0*time.Second))
|
||||
|
||||
@@ -65,8 +65,8 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
|
||||
}
|
||||
|
||||
maxRuntimeInMinutes := time.Duration(config.MaxRuntimeInMinutes) * time.Minute
|
||||
pollIntervalsInMilliseconds := time.Duration(config.PollIntervalsInMilliseconds) * time.Millisecond
|
||||
builds, err := executeBuilds(addonDescriptor.Repositories, *conn, maxRuntimeInMinutes, pollIntervalsInMilliseconds)
|
||||
pollInterval := time.Duration(config.PollIntervalsInMilliseconds) * time.Millisecond
|
||||
builds, err := executeBuilds(addonDescriptor.Repositories, *conn, maxRuntimeInMinutes, pollInterval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Starting Builds for Repositories with reserved AAKaaS packages failed")
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
|
||||
return nil
|
||||
}
|
||||
|
||||
func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollIntervalsInMilliseconds time.Duration) ([]buildWithRepository, error) {
|
||||
func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) ([]buildWithRepository, error) {
|
||||
var builds []buildWithRepository
|
||||
|
||||
for _, repo := range repos {
|
||||
@@ -115,13 +115,14 @@ func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRu
|
||||
}
|
||||
|
||||
if repo.Status == "P" {
|
||||
buildRepo.repo.InBuildScope = true
|
||||
err := buildRepo.start()
|
||||
if err != nil {
|
||||
buildRepo.build.RunState = abapbuild.Failed
|
||||
log.Entry().Error(err)
|
||||
log.Entry().Info("Continueing with other builds (if any)")
|
||||
} else {
|
||||
err = buildRepo.waitToBeFinished(maxRuntimeInMinutes, pollIntervalsInMilliseconds)
|
||||
err = buildRepo.waitToBeFinished(maxRuntimeInMinutes, pollInterval)
|
||||
if err != nil {
|
||||
buildRepo.build.RunState = abapbuild.Failed
|
||||
log.Entry().Error(err)
|
||||
@@ -137,9 +138,9 @@ func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRu
|
||||
return builds, nil
|
||||
}
|
||||
|
||||
func (br *buildWithRepository) waitToBeFinished(maxRuntimeInMinutes time.Duration, pollIntervalsInMilliseconds time.Duration) error {
|
||||
func (br *buildWithRepository) waitToBeFinished(maxRuntimeInMinutes time.Duration, pollInterval time.Duration) error {
|
||||
timeout := time.After(maxRuntimeInMinutes)
|
||||
ticker := time.Tick(pollIntervalsInMilliseconds)
|
||||
ticker := time.Tick(pollInterval)
|
||||
for {
|
||||
select {
|
||||
case <-timeout:
|
||||
@@ -147,7 +148,7 @@ func (br *buildWithRepository) waitToBeFinished(maxRuntimeInMinutes time.Duratio
|
||||
case <-ticker:
|
||||
br.build.Get()
|
||||
if !br.build.IsFinished() {
|
||||
log.Entry().Infof("Assembly of %s is not yet finished, check again in %s", br.repo.PackageName, pollIntervalsInMilliseconds)
|
||||
log.Entry().Infof("Assembly of %s is not yet finished, check again in %s", br.repo.PackageName, pollInterval)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
@@ -251,25 +252,3 @@ func checkIfFailedAndPrintLogs(builds []buildWithRepository) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadSARXML(builds []buildWithRepository) ([]abaputils.Repository, error) {
|
||||
var reposBackToCPE []abaputils.Repository
|
||||
resultName := "SAR_XML"
|
||||
envPath := filepath.Join(GeneralConfig.EnvRootPath, "commonPipelineEnvironment", "abap")
|
||||
for i, b := range builds {
|
||||
resultSARXML, err := b.build.GetResult(resultName)
|
||||
if err != nil {
|
||||
return reposBackToCPE, err
|
||||
}
|
||||
sarPackage := resultSARXML.AdditionalInfo
|
||||
downloadPath := filepath.Join(envPath, path.Base(sarPackage))
|
||||
log.Entry().Infof("Downloading SAR file %s to %s", path.Base(sarPackage), downloadPath)
|
||||
err = resultSARXML.Download(downloadPath)
|
||||
if err != nil {
|
||||
return reposBackToCPE, err
|
||||
}
|
||||
builds[i].repo.SarXMLFilePath = downloadPath
|
||||
reposBackToCPE = append(reposBackToCPE, builds[i].repo)
|
||||
}
|
||||
return reposBackToCPE, nil
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ func TestStep(t *testing.T) {
|
||||
|
||||
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":false`)
|
||||
})
|
||||
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
|
||||
|
||||
@@ -104,6 +105,7 @@ func TestStep(t *testing.T) {
|
||||
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, cpe.abap.addonDescriptor, `SAPK-001AAINITAPC1.SAR`)
|
||||
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":true`)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user