github.com/SAP/jenkins-library@v1.362.0/cmd/abapAddonAssemblyKitCheckPV.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/SAP/jenkins-library/pkg/abap/aakaas"
     5  	abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
     6  	"github.com/SAP/jenkins-library/pkg/abaputils"
     7  	"github.com/SAP/jenkins-library/pkg/log"
     8  	"github.com/SAP/jenkins-library/pkg/piperutils"
     9  	"github.com/SAP/jenkins-library/pkg/telemetry"
    10  )
    11  
    12  func abapAddonAssemblyKitCheckPV(config abapAddonAssemblyKitCheckPVOptions, telemetryData *telemetry.CustomData, cpe *abapAddonAssemblyKitCheckPVCommonPipelineEnvironment) {
    13  	utils := aakaas.NewAakBundle()
    14  	// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
    15  	if err := runAbapAddonAssemblyKitCheckPV(&config, telemetryData, utils, cpe); err != nil {
    16  		log.Entry().WithError(err).Fatal("step execution failed")
    17  	}
    18  }
    19  func runAbapAddonAssemblyKitCheckPV(config *abapAddonAssemblyKitCheckPVOptions, telemetryData *telemetry.CustomData, utils aakaas.AakUtils, cpe *abapAddonAssemblyKitCheckPVCommonPipelineEnvironment) error {
    20  
    21  	log.Entry().Info("╔═════════════════════════════╗")
    22  	log.Entry().Info("║ abapAddonAssemblyKitCheckPV ║")
    23  	log.Entry().Info("╚═════════════════════════════╝")
    24  
    25  	conn := new(abapbuild.Connector)
    26  	if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, utils, "", config.AbapAddonAssemblyKitCertificateFile, config.AbapAddonAssemblyKitCertificatePass); err != nil {
    27  		return err
    28  	}
    29  
    30  	log.Entry().Infof("Reading Product Version Information from addonDescriptor (aka addon.yml) file: %s", config.AddonDescriptorFileName)
    31  	addonDescriptor, err := utils.ReadAddonDescriptor(config.AddonDescriptorFileName)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	pv := new(aakaas.ProductVersion)
    37  	if err := pv.ConstructProductversion(addonDescriptor, *conn); err != nil {
    38  		return err
    39  	}
    40  	if err = pv.ValidateAndResolveVersionFields(); err != nil {
    41  		return err
    42  	}
    43  	pv.CopyVersionFieldsToDescriptor(&addonDescriptor)
    44  
    45  	// now Product Version fields are valid, but maybe Component Versions (Repositories) were checked before, so copy that part from CPE
    46  	// we don't care for errors
    47  	// scenario 1: config.AddonDescriptor is empty since checkPV is the first step in the pipeline, then the empty result is fine anyway
    48  	// scenario 2: for some reason config.AddonDescriptor is corrupt - then we insert the valid data but delete the repositories which will ensure issue is found later on
    49  	addonDescriptorCPE, _ := abaputils.ConstructAddonDescriptorFromJSON([]byte(config.AddonDescriptor))
    50  	if len(addonDescriptorCPE.Repositories) == 0 {
    51  		log.Entry().Info("No Software Component Information present yet in the addonDescriptor of CommonPipelineEnvironment")
    52  	} else {
    53  		log.Entry().Infof("Information for %v Software Component Repositories taken from addonDescriptor of CommonPipelineEnvironment", len(addonDescriptorCPE.Repositories))
    54  	}
    55  	addonDescriptor.SetRepositories(addonDescriptorCPE.Repositories)
    56  	cpe.abap.addonDescriptor = string(addonDescriptor.AsJSON())
    57  	log.Entry().Info("Wrote addonDescriptor to CommonPipelineEnvironment")
    58  
    59  	var filesToPublish []piperutils.Path
    60  	log.Entry().Infof("Add %s to be published", config.AddonDescriptorFileName)
    61  	filesToPublish = append(filesToPublish, piperutils.Path{Target: config.AddonDescriptorFileName, Name: "AddonDescriptor", Mandatory: true})
    62  	log.Entry().Infof("Publishing %v files", len(filesToPublish))
    63  	if err := piperutils.PersistReportsAndLinks("abapAddonAssemblyKitCheckPV", "", utils, filesToPublish, nil); err != nil {
    64  		log.Entry().WithError(err).Error("failed to persist report information")
    65  	}
    66  
    67  	return nil
    68  }