mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
feat(mavenBuild): accept build profiles (#2921)
This commit is contained in:
parent
49dfc1f422
commit
8883a5148c
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/command"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
@ -30,6 +31,10 @@ func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomDat
|
||||
|
||||
var flags = []string{"-update-snapshots", "--batch-mode"}
|
||||
|
||||
if len(config.Profiles) > 0 {
|
||||
flags = append(flags, "--activate-profiles", strings.Join(config.Profiles, ","))
|
||||
}
|
||||
|
||||
exists, _ := utils.FileExists("integration-tests/pom.xml")
|
||||
if exists {
|
||||
flags = append(flags, "-pl", "!integration-tests")
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
|
||||
type mavenBuildOptions struct {
|
||||
PomPath string `json:"pomPath,omitempty"`
|
||||
Profiles []string `json:"profiles,omitempty"`
|
||||
Flatten bool `json:"flatten,omitempty"`
|
||||
Verify bool `json:"verify,omitempty"`
|
||||
ProjectSettingsFile string `json:"projectSettingsFile,omitempty"`
|
||||
@ -108,6 +109,7 @@ supports ci friendly versioning by flattening the pom before installing.`,
|
||||
|
||||
func addMavenBuildFlags(cmd *cobra.Command, stepConfig *mavenBuildOptions) {
|
||||
cmd.Flags().StringVar(&stepConfig.PomPath, "pomPath", `pom.xml`, "Path to the pom file which should be installed including all children.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.Profiles, "profiles", []string{}, "Defines list of maven build profiles to be used.")
|
||||
cmd.Flags().BoolVar(&stepConfig.Flatten, "flatten", true, "Defines if the pom files should be flattened to support ci friendly maven versioning.")
|
||||
cmd.Flags().BoolVar(&stepConfig.Verify, "verify", false, "Instead of installing the artifact only the verify lifecycle phase is executed.")
|
||||
cmd.Flags().StringVar(&stepConfig.ProjectSettingsFile, "projectSettingsFile", os.Getenv("PIPER_projectSettingsFile"), "Path to the mvn settings file that should be used as project settings file.")
|
||||
@ -147,6 +149,15 @@ func mavenBuildMetadata() config.StepData {
|
||||
Aliases: []config.Alias{},
|
||||
Default: `pom.xml`,
|
||||
},
|
||||
{
|
||||
Name: "profiles",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"},
|
||||
Type: "[]string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
Default: []string{},
|
||||
},
|
||||
{
|
||||
Name: "flatten",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
|
@ -116,4 +116,16 @@ func TestMavenBuild(t *testing.T) {
|
||||
assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::default::http://sampleRepo.com")
|
||||
})
|
||||
|
||||
t.Run("mavenBuild accepts profiles", func(t *testing.T) {
|
||||
mockedUtils := newMavenMockUtils()
|
||||
|
||||
config := mavenBuildOptions{Profiles: []string{"profile1", "profile2"}}
|
||||
|
||||
err := runMavenBuild(&config, nil, &mockedUtils)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Contains(t, mockedUtils.Calls[0].Params, "--activate-profiles")
|
||||
assert.Contains(t, mockedUtils.Calls[0].Params, "profile1,profile2")
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,14 @@ spec:
|
||||
- STEPS
|
||||
mandatory: false
|
||||
default: pom.xml
|
||||
- name: profiles
|
||||
type: "[]string"
|
||||
description: Defines list of maven build profiles to be used.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- GENERAL
|
||||
- STAGES
|
||||
- STEPS
|
||||
- name: flatten
|
||||
type: bool
|
||||
description: Defines if the pom files should be flattened to support ci friendly maven versioning.
|
||||
|
Loading…
x
Reference in New Issue
Block a user