1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/mavenExecute.go

44 lines
1.4 KiB
Go
Raw Normal View History

2020-02-28 14:09:46 +02:00
package cmd
import (
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/maven"
sliceUtils "github.com/SAP/jenkins-library/pkg/piperutils"
"io/ioutil"
2020-02-28 14:09:46 +02:00
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func mavenExecute(config mavenExecuteOptions, _ *telemetry.CustomData) {
runner := command.Command{}
err := runMavenExecute(config, &runner)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
2020-02-28 14:09:46 +02:00
func runMavenExecute(config mavenExecuteOptions, runner execRunner) error {
2020-02-28 14:09:46 +02:00
options := maven.ExecuteOptions{
PomPath: config.PomPath,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
Goals: splitTrimAndDeDupParams(config.Goals),
Defines: splitTrimAndDeDupParams(config.Defines),
Flags: splitTrimAndDeDupParams(config.Flags),
2020-02-28 14:09:46 +02:00
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
ReturnStdout: config.ReturnStdout,
}
output, err := maven.Execute(&options, runner)
if err == nil && config.ReturnStdout {
err = ioutil.WriteFile(".pipeline/maven_output.txt", []byte(output), 0644)
2020-02-28 14:09:46 +02:00
}
return err
}
2020-02-28 14:09:46 +02:00
func splitTrimAndDeDupParams(params []string) []string {
return sliceUtils.SplitTrimAndDeDup(params, " ")
2020-02-28 14:09:46 +02:00
}