mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
427f78b3ed
* adding my steps * messy step * Update abapEnvironmentAssembly.go * clean up * change yaml * corrections * Update cloudFoundryDeploy.go * update * delete simulation step * remove simulate * Update PiperGoUtils.groovy * Update PiperGoUtils.groovy * Update CommonStepsTest.groovy * add docu * Update abapEnvironmentAssembly.md * changes due to PR * Update .gitignore * b * CV list * Update abapEnvironmentAssembly.go * testing with simulation * Update abapEnvironmentAssembly.go * remove simulation * renaming * Update mkdocs.yml * moving service key to yaml and fixing code climate * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * Update abapEnvironmentAssemblePackages.go * change input * Update abapEnvironmentAssemblePackages.go * change json tag * fixed error handling * documentation * Update abapEnvironmentAssemblePackages.md * Update abapEnvironmentAssemblePackages.md * fixing code climate issues * fixing code climate issues * Update abapEnvironmentAssemblePackages.yaml * fixing code climate issues * Update abapEnvironmentAssemblePackages.yaml * adding unittests * adding unittests and improved logging * yaml -> json * change scope of cfServiceKeyName * correct indentation * Update CommonStepsTest.groovy * maintain correct step order * AAKaaS CheckPV step * AAKaaS CheckPV step #2 * AAKaaS CheckPV step #3 * AAKaaS CheckPV step #4 * AAKaaS CheckPV step #5 * Update resources/metadata/abapAddonAssemblyKitCheckCVs.yaml Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * Update resources/metadata/abapAddonAssemblyKitCheckPV.yaml Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * Update resources/metadata/abapAddonAssemblyKitCheckPV.yaml Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * Update resources/metadata/abapAddonAssemblyKitCheckCVs.yaml Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * AAKaaS CheckPV step #6 Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com> Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
104 lines
3.8 KiB
Go
104 lines
3.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
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"
|
|
)
|
|
|
|
func abapAddonAssemblyKitCheckCVs(config abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment) {
|
|
// 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 := runAbapAddonAssemblyKitCheckCVs(&config, telemetryData, &client, cpe, abaputils.ReadAddonDescriptor)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
}
|
|
}
|
|
|
|
func runAbapAddonAssemblyKitCheckCVs(config *abapAddonAssemblyKitCheckCVsOptions, telemetryData *telemetry.CustomData, client piperhttp.Sender,
|
|
cpe *abapAddonAssemblyKitCheckCVsCommonPipelineEnvironment, readAdoDescriptor abaputils.ReadAddonDescriptorType) error {
|
|
var addonDescriptorFromCPE abaputils.AddonDescriptor
|
|
json.Unmarshal([]byte(config.AddonDescriptor), &addonDescriptorFromCPE)
|
|
addonDescriptor, err := readAdoDescriptor(config.AddonDescriptorFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
addonDescriptor = combineYAMLRepositoriesWithCPEProduct(addonDescriptor, addonDescriptorFromCPE)
|
|
conn := new(abapbuild.Connector)
|
|
conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client)
|
|
|
|
for i := range addonDescriptor.Repositories {
|
|
var c componentVersion
|
|
c.initCV(addonDescriptor.Repositories[i], *conn)
|
|
err := c.validate()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.copyFieldsToRepo(&addonDescriptor.Repositories[i])
|
|
}
|
|
log.Entry().Info("Write the resolved versions to the CommonPipelineEnvironment")
|
|
toCPE, _ := json.Marshal(addonDescriptor)
|
|
cpe.abap.addonDescriptor = string(toCPE)
|
|
return nil
|
|
}
|
|
|
|
//take the product part from CPE and the repositories part from the YAML file
|
|
func combineYAMLRepositoriesWithCPEProduct(addonDescriptor abaputils.AddonDescriptor, addonDescriptorFromCPE abaputils.AddonDescriptor) abaputils.AddonDescriptor {
|
|
addonDescriptorFromCPE.Repositories = addonDescriptor.Repositories
|
|
return addonDescriptorFromCPE
|
|
}
|
|
|
|
func (c *componentVersion) initCV(repo abaputils.Repository, conn abapbuild.Connector) {
|
|
c.Connector = conn
|
|
c.Name = repo.Name
|
|
c.VersionYAML = repo.VersionYAML
|
|
}
|
|
|
|
func (c *componentVersion) copyFieldsToRepo(initialRepo *abaputils.Repository) {
|
|
initialRepo.Version = c.Version
|
|
initialRepo.SpLevel = c.SpLevel
|
|
initialRepo.PatchLevel = c.PatchLevel
|
|
}
|
|
|
|
func (c *componentVersion) validate() error {
|
|
log.Entry().Infof("Validate component %s version %s and resolve version", c.Name, c.VersionYAML)
|
|
appendum := "/odata/aas_ocs_package/ValidateComponentVersion?Name='" + c.Name + "'&Version='" + c.VersionYAML + "'"
|
|
body, err := c.Connector.Get(appendum)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var jCV jsonComponentVersion
|
|
json.Unmarshal(body, &jCV)
|
|
c.Name = jCV.ComponentVersion.Name
|
|
c.Version = jCV.ComponentVersion.Version
|
|
c.SpLevel = jCV.ComponentVersion.SpLevel
|
|
c.PatchLevel = jCV.ComponentVersion.PatchLevel
|
|
log.Entry().Infof("Resolved version %s, splevel %s, patchlevel %s", c.Version, c.SpLevel, c.PatchLevel)
|
|
return nil
|
|
}
|
|
|
|
type jsonComponentVersion struct {
|
|
ComponentVersion *componentVersion `json:"d"`
|
|
}
|
|
|
|
type componentVersion struct {
|
|
abapbuild.Connector
|
|
Name string `json:"Name"`
|
|
VersionYAML string
|
|
Version string `json:"Version"`
|
|
SpLevel string `json:"SpLevel"`
|
|
PatchLevel string `json:"PatchLevel"`
|
|
}
|