1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/mavenBuild.go
Nikolai Demidenko eb87a2c976
Add createBOM parameter to the mavenBuild step (#2639)
* Add createBOM parameter to the mavenBuild step

* update generated files

* Update resources/metadata/mavenBuild.yaml

* Update resources/metadata/mavenBuild.yaml

* update generated mavenBuild

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-02-25 15:01:19 +01:00

72 lines
2.0 KiB
Go

package cmd
import (
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/maven"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func mavenBuild(config mavenBuildOptions, telemetryData *telemetry.CustomData) {
utils := maven.NewUtilsBundle()
err := runMavenBuild(&config, telemetryData, utils)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomData, utils maven.Utils) error {
var flags = []string{"-update-snapshots", "--batch-mode"}
exists, _ := utils.FileExists("integration-tests/pom.xml")
if exists {
flags = append(flags, "-pl", "!integration-tests")
}
var defines []string
var goals []string
goals = append(goals, "org.jacoco:jacoco-maven-plugin:prepare-agent")
if config.Flatten {
goals = append(goals, "flatten:flatten")
defines = append(defines, "-Dflatten.mode=resolveCiFriendliesOnly", "-DupdatePomFile=true")
}
if config.CreateBOM {
goals = append(goals, "org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom")
createBOMConfig := []string{
"-DschemaVersion=1.2",
"-DincludeBomSerialNumber=true",
"-DincludeCompileScope=true",
"-DincludeProvidedScope=true",
"-DincludeRuntimeScope=true",
"-DincludeSystemScope=true",
"-DincludeTestScope=false",
"-DincludeLicenseText=false",
"-DoutputFormat=xml",
}
defines = append(defines, createBOMConfig...)
}
if config.Verify {
goals = append(goals, "verify")
} else {
goals = append(goals, "install")
}
mavenOptions := maven.ExecuteOptions{
Flags: flags,
Goals: goals,
Defines: defines,
PomPath: config.PomPath,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
}
_, err := maven.Execute(&mavenOptions, utils)
return err
}