1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/tmsExport.go
gerstneralex f5c33d51bb
Tms export (#4160)
* Change parameter type of nodeExtDescriptorMapping

(cherry picked from commit ca7ce0485a)

* Remove usage of the depricated ioutil package

(cherry picked from commit 9821915b33)

* Fix cmd failure if neither git/commitId nor customDescription are
provided

(cherry picked from commit c362681e45)

* Fix unit test

(cherry picked from commit 53a90aabb5)

* Step metadata, step code generation

* change type of nodeExtDescriptorMapping for export

* Refactoring and export implementation

* integration test

* Add export step

* Integration test

* format

* discard piper.go

* Review related changes

* restore piper.go

* remove unused method

* Extend documentation

* Add parameter useGoStep to tmsUpload.groovy

* Regenerate steps

* Rename function

* refactor constants

* Add error path tests

* Move some code to tms package

* Move more code to tms

* Combine tmsUpload, tmsUtils

* Add groovy wrapper

* add parameters to groovy step

* add import

* jenkinsUtils instance

* comment namedUser logic in groovy

* namedUser param

* remove logic for namedUser param

* Remove TMS integration tests

* discard changes in tmsUpload.groovy

* Remove parameters

* Restore parameters

* Change type of NodeExtDescriptorMapping to map[string]interface{}

* tmsUpload: Change type of NodeExtDescriptorMapping to map

* Resolve ioutil deprecation

* Review related changes

* Formatting

* Review related improvements

* Add tmsUtils test

* Formatting tmsUtils_test

* Remove parameters from groovy wrapper

* Remove tmsUtils_test

* Add TMS steps to fieldRelatedWhitelist

* Add integration test

* Add test to github_actions_integration_test_list.yml

* Move test helper method

* Step documentation placeholder

* Remove parameter StashContent

* Restore cmd/integrationArtifactTransport.go

---------

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
2023-03-27 16:55:29 +02:00

66 lines
2.1 KiB
Go

package cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/SAP/jenkins-library/pkg/tms"
)
type tmsExportUtilsBundle struct {
*command.Command
*piperutils.Files
}
func tmsExport(exportConfig tmsExportOptions, telemetryData *telemetry.CustomData, influx *tmsExportInflux) {
utils := tms.NewTmsUtils()
config := convertExportOptions(exportConfig)
communicationInstance := tms.SetupCommunication(config)
err := runTmsExport(exportConfig, communicationInstance, utils)
if err != nil {
log.Entry().WithError(err).Fatal("Failed to run tmsExport")
}
}
func runTmsExport(exportConfig tmsExportOptions, communicationInstance tms.CommunicationInterface, utils tms.TmsUtils) error {
config := convertExportOptions(exportConfig)
fileId, errUploadFile := tms.UploadFile(config, communicationInstance, utils)
if errUploadFile != nil {
return errUploadFile
}
errUploadDescriptors := tms.UploadDescriptors(config, communicationInstance, utils)
if errUploadDescriptors != nil {
return errUploadDescriptors
}
_, errExportFileToNode := communicationInstance.ExportFileToNode(config.NodeName, fileId, config.CustomDescription, config.NamedUser)
if errExportFileToNode != nil {
log.SetErrorCategory(log.ErrorService)
return fmt.Errorf("failed to export file to node: %w", errExportFileToNode)
}
return nil
}
func convertExportOptions(exportConfig tmsExportOptions) tms.Options {
var config tms.Options
config.TmsServiceKey = exportConfig.TmsServiceKey
config.CustomDescription = exportConfig.CustomDescription
if config.CustomDescription == "" {
config.CustomDescription = tms.DEFAULT_TR_DESCRIPTION
}
config.NamedUser = exportConfig.NamedUser
config.NodeName = exportConfig.NodeName
config.MtaPath = exportConfig.MtaPath
config.MtaVersion = exportConfig.MtaVersion
config.NodeExtDescriptorMapping = exportConfig.NodeExtDescriptorMapping
config.Proxy = exportConfig.Proxy
config.Verbose = GeneralConfig.Verbose
return config
}