1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/mavenExecute.go
Florian Wilhelm eaf5479e9c
Fix maven parameter handling (#1493)
Avoid maven error `Unknown lifecycle phase \"-\"` when the value of a define contains `-`.

Don't split and trim maven arguments. Expect they come in as a list, keep them as list.

This is a breaking change compared to the old Groovy implementation which relied on using a shell for calling maven.

As an example, consider this diff:

```diff
-        goals: 'org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate',
-        defines: "-Dexpression=$pomPathExpression -DforceStdout -q",
+        goals: ['org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate'],
+        defines: ["-Dexpression=$pomPathExpression", "-DforceStdout", "-q"],
```
2020-05-06 17:43:32 +02:00

41 lines
1.2 KiB
Go

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