mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
Provide addonDescriptor to build System (#4914)
This commit is contained in:
parent
7d9fc6aee4
commit
0aac69625e
@ -50,7 +50,7 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
|
|||||||
return errors.Wrap(err, "Reading AddonDescriptor failed [Make sure abapAddonAssemblyKit...CheckCVs|CheckPV|ReserveNextPackages steps have been run before]")
|
return errors.Wrap(err, "Reading AddonDescriptor failed [Make sure abapAddonAssemblyKit...CheckCVs|CheckPV|ReserveNextPackages steps have been run before]")
|
||||||
}
|
}
|
||||||
|
|
||||||
builds, err := executeBuilds(addonDescriptor.Repositories, *connBuild, time.Duration(config.MaxRuntimeInMinutes)*time.Minute, time.Duration(config.PollIntervalsInMilliseconds)*time.Millisecond)
|
builds, err := executeBuilds(addonDescriptor, *connBuild, time.Duration(config.MaxRuntimeInMinutes)*time.Minute, time.Duration(config.PollIntervalsInMilliseconds)*time.Millisecond)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Starting Builds for Repositories with reserved AAKaaS packages failed")
|
return errors.Wrap(err, "Starting Builds for Repositories with reserved AAKaaS packages failed")
|
||||||
}
|
}
|
||||||
@ -84,10 +84,10 @@ func runAbapEnvironmentAssemblePackages(config *abapEnvironmentAssemblePackagesO
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) ([]buildWithRepository, error) {
|
func executeBuilds(addonDescriptor *abaputils.AddonDescriptor, conn abapbuild.Connector, maxRuntimeInMinutes time.Duration, pollInterval time.Duration) ([]buildWithRepository, error) {
|
||||||
var builds []buildWithRepository
|
var builds []buildWithRepository
|
||||||
|
|
||||||
for _, repo := range repos {
|
for _, repo := range addonDescriptor.Repositories {
|
||||||
|
|
||||||
buildRepo := buildWithRepository{
|
buildRepo := buildWithRepository{
|
||||||
build: abapbuild.Build{
|
build: abapbuild.Build{
|
||||||
@ -98,7 +98,7 @@ func executeBuilds(repos []abaputils.Repository, conn abapbuild.Connector, maxRu
|
|||||||
|
|
||||||
if repo.Status == "P" {
|
if repo.Status == "P" {
|
||||||
buildRepo.repo.InBuildScope = true
|
buildRepo.repo.InBuildScope = true
|
||||||
err := buildRepo.start()
|
err := buildRepo.start(addonDescriptor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
buildRepo.build.RunState = abapbuild.Failed
|
buildRepo.build.RunState = abapbuild.Failed
|
||||||
log.Entry().Error(err)
|
log.Entry().Error(err)
|
||||||
@ -140,7 +140,7 @@ func (br *buildWithRepository) waitToBeFinished(maxRuntimeInMinutes time.Duratio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *buildWithRepository) start() error {
|
func (br *buildWithRepository) start(addonDescriptor *abaputils.AddonDescriptor) error {
|
||||||
if br.repo.Name == "" || br.repo.Version == "" || br.repo.SpLevel == "" || br.repo.PackageType == "" || br.repo.PackageName == "" {
|
if br.repo.Name == "" || br.repo.Version == "" || br.repo.SpLevel == "" || br.repo.PackageType == "" || br.repo.PackageName == "" {
|
||||||
return errors.New("Parameters missing. Please provide software component name, version, sp-level, packagetype and packagename")
|
return errors.New("Parameters missing. Please provide software component name, version, sp-level, packagetype and packagename")
|
||||||
}
|
}
|
||||||
@ -166,6 +166,10 @@ func (br *buildWithRepository) start() error {
|
|||||||
ValueID: "PACKAGE_NAME_" + br.repo.PackageType,
|
ValueID: "PACKAGE_NAME_" + br.repo.PackageType,
|
||||||
Value: br.repo.PackageName,
|
Value: br.repo.PackageName,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ValueID: "addonDescriptor",
|
||||||
|
Value: addonDescriptor.AsReducedJson(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if br.repo.Namespace != "" {
|
if br.repo.Namespace != "" {
|
||||||
|
@ -64,13 +64,15 @@ func TestStartingInvalidInput(t *testing.T) {
|
|||||||
conn := new(abapbuild.Connector)
|
conn := new(abapbuild.Connector)
|
||||||
conn.Client = client
|
conn.Client = client
|
||||||
conn.Header = make(map[string][]string)
|
conn.Header = make(map[string][]string)
|
||||||
var repos []abaputils.Repository
|
aD := abaputils.AddonDescriptor{
|
||||||
repo := abaputils.Repository{
|
Repositories: []abaputils.Repository{
|
||||||
Name: "RepoA",
|
{
|
||||||
Status: "P",
|
Name: "RepoA",
|
||||||
|
Status: "P",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
repos = append(repos, repo)
|
builds, err := executeBuilds(&aD, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
|
||||||
builds, err := executeBuilds(repos, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 1, len(builds))
|
assert.Equal(t, 1, len(builds))
|
||||||
assert.Equal(t, abapbuild.Failed, builds[0].build.RunState)
|
assert.Equal(t, abapbuild.Failed, builds[0].build.RunState)
|
||||||
@ -95,7 +97,7 @@ func TestStep(t *testing.T) {
|
|||||||
|
|
||||||
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &mock.FilesMock{}, &client, cpe)
|
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &mock.FilesMock{}, &client, cpe)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Contains(t, cpe.abap.addonDescriptor, `"InBuildScope":false`)
|
assert.NotContains(t, cpe.abap.addonDescriptor, `"InBuildScope"`)
|
||||||
})
|
})
|
||||||
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
|
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
|
||||||
config := &abapEnvironmentAssemblePackagesOptions{
|
config := &abapEnvironmentAssemblePackagesOptions{
|
||||||
|
@ -26,34 +26,34 @@ import (
|
|||||||
// AddonDescriptor contains fields about the addonProduct
|
// AddonDescriptor contains fields about the addonProduct
|
||||||
type AddonDescriptor struct {
|
type AddonDescriptor struct {
|
||||||
AddonProduct string `json:"addonProduct"`
|
AddonProduct string `json:"addonProduct"`
|
||||||
AddonVersionYAML string `json:"addonVersion"`
|
AddonVersionYAML string `json:"addonVersion,omitempty"`
|
||||||
AddonVersion string `json:"addonVersionAAK"`
|
AddonVersion string `json:"addonVersionAAK"`
|
||||||
AddonSpsLevel string
|
AddonSpsLevel string
|
||||||
AddonPatchLevel string
|
AddonPatchLevel string
|
||||||
TargetVectorID string
|
TargetVectorID string `json:",omitempty"`
|
||||||
Repositories []Repository `json:"repositories"`
|
Repositories []Repository `json:"repositories"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repository contains fields for the repository/component version
|
// Repository contains fields for the repository/component version
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
UseClassicCTS bool `json:"useClassicCTS"`
|
UseClassicCTS bool `json:"useClassicCTS,omitempty"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag,omitempty"`
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch,omitempty"`
|
||||||
CommitID string `json:"commitID"`
|
CommitID string `json:"commitID,omitempty"`
|
||||||
VersionYAML string `json:"version"`
|
VersionYAML string `json:"version,omitempty"`
|
||||||
Version string `json:"versionAAK"`
|
Version string `json:"versionAAK"`
|
||||||
AdditionalPiecelist string `json:"additionalPiecelist"`
|
AdditionalPiecelist string `json:"additionalPiecelist,omitempty"`
|
||||||
PackageName string
|
PackageName string `json:",omitempty"`
|
||||||
PackageType string
|
PackageType string `json:",omitempty"`
|
||||||
SpLevel string
|
SpLevel string
|
||||||
PatchLevel string
|
PatchLevel string
|
||||||
PredecessorCommitID string
|
PredecessorCommitID string `json:",omitempty"`
|
||||||
Status string
|
Status string `json:",omitempty"`
|
||||||
Namespace string
|
Namespace string `json:",omitempty"`
|
||||||
SarXMLFilePath string
|
SarXMLFilePath string `json:",omitempty"`
|
||||||
Languages []string `json:"languages"`
|
Languages []string `json:"languages,omitempty"`
|
||||||
InBuildScope bool
|
InBuildScope bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadAddonDescriptorType is the type for ReadAddonDescriptor for mocking
|
// ReadAddonDescriptorType is the type for ReadAddonDescriptor for mocking
|
||||||
@ -182,3 +182,22 @@ func (me *AddonDescriptor) GetRepositoriesInBuildScope() []Repository {
|
|||||||
}
|
}
|
||||||
return RepositoriesInBuildScope
|
return RepositoriesInBuildScope
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *AddonDescriptor) AsReducedJson() string {
|
||||||
|
input := AddonDescriptor{
|
||||||
|
AddonProduct: me.AddonProduct,
|
||||||
|
AddonVersion: me.AddonVersion,
|
||||||
|
AddonSpsLevel: me.AddonSpsLevel,
|
||||||
|
AddonPatchLevel: me.AddonPatchLevel,
|
||||||
|
}
|
||||||
|
for _, repo := range me.Repositories {
|
||||||
|
input.Repositories = append(input.Repositories, Repository{
|
||||||
|
Name: repo.Name,
|
||||||
|
Version: repo.Version,
|
||||||
|
SpLevel: repo.SpLevel,
|
||||||
|
PatchLevel: repo.PatchLevel,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return input.AsJSONstring()
|
||||||
|
}
|
||||||
|
@ -40,6 +40,9 @@ func TestAddonDescriptorNew(t *testing.T) {
|
|||||||
assert.Equal(t, "/DMO/REPO_B", repos[0].Name)
|
assert.Equal(t, "/DMO/REPO_B", repos[0].Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("AsReducedJson", func(t *testing.T) {
|
||||||
|
assert.NotContains(t, "commitID", addonDescriptor.AsReducedJson())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAddonDescriptorYAML = `---
|
var TestAddonDescriptorYAML = `---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user