2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
|
|
|
import com.sap.piper.Utils
|
|
|
|
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field def STEP_NAME = getClass().getName()
|
2018-08-15 11:53:28 +02:00
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
|
|
'dockerImage',
|
|
|
|
'globalSettingsFile',
|
|
|
|
'projectSettingsFile',
|
|
|
|
'pomPath',
|
|
|
|
'm2Path'
|
|
|
|
]
|
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
|
|
|
'dockerOptions',
|
|
|
|
'flags',
|
|
|
|
'goals',
|
|
|
|
'defines',
|
|
|
|
'logSuccessfulMavenTransfers'
|
|
|
|
])
|
2017-12-06 13:03:06 +02:00
|
|
|
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2018-08-15 11:53:28 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2018-09-21 16:55:31 +02:00
|
|
|
|
2018-10-31 09:40:12 +02:00
|
|
|
final script = checkScript(this, parameters) ?: this
|
2017-12-06 13:03:06 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
// load default & individual configuration
|
2018-10-17 11:05:20 +02:00
|
|
|
Map configuration = ConfigurationHelper.newInstance(this)
|
2018-09-07 10:08:16 +02:00
|
|
|
.loadStepDefaults()
|
2018-08-15 11:53:28 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
2019-01-21 09:47:34 +02:00
|
|
|
new Utils().pushToSWA([
|
|
|
|
step: STEP_NAME,
|
|
|
|
stepParamKey1: 'scriptMissing',
|
|
|
|
stepParam1: parameters?.script == null
|
|
|
|
], configuration)
|
2017-12-06 13:03:06 +02:00
|
|
|
|
|
|
|
String command = "mvn"
|
|
|
|
|
|
|
|
def globalSettingsFile = configuration.globalSettingsFile
|
|
|
|
if (globalSettingsFile?.trim()) {
|
|
|
|
if(globalSettingsFile.trim().startsWith("http")){
|
|
|
|
downloadSettingsFromUrl(globalSettingsFile)
|
|
|
|
globalSettingsFile = "settings.xml"
|
|
|
|
}
|
|
|
|
command += " --global-settings '${globalSettingsFile}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def m2Path = configuration.m2Path
|
|
|
|
if(m2Path?.trim()) {
|
|
|
|
command += " -Dmaven.repo.local='${m2Path}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def projectSettingsFile = configuration.projectSettingsFile
|
|
|
|
if (projectSettingsFile?.trim()) {
|
|
|
|
if(projectSettingsFile.trim().startsWith("http")){
|
|
|
|
downloadSettingsFromUrl(projectSettingsFile)
|
|
|
|
projectSettingsFile = "settings.xml"
|
|
|
|
}
|
|
|
|
command += " --settings '${projectSettingsFile}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def pomPath = configuration.pomPath
|
|
|
|
if(pomPath?.trim()){
|
|
|
|
command += " --file '${pomPath}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def mavenFlags = configuration.flags
|
|
|
|
if (mavenFlags?.trim()) {
|
|
|
|
command += " ${mavenFlags}"
|
|
|
|
}
|
|
|
|
|
2018-06-06 14:42:47 +02:00
|
|
|
// Always use Maven's batch mode
|
2018-07-26 16:03:05 +02:00
|
|
|
if (!(command =~ /--batch-mode|-B(?=\s)|-B\\|-B$/)) {
|
2018-06-06 14:42:47 +02:00
|
|
|
command += ' --batch-mode'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable log for successful transfers by default. Note this requires the batch-mode flag.
|
|
|
|
final String disableSuccessfulMavenTransfersLogFlag = ' -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
|
|
|
|
if (!configuration.logSuccessfulMavenTransfers) {
|
|
|
|
if (!command.contains(disableSuccessfulMavenTransfersLogFlag)) {
|
|
|
|
command += disableSuccessfulMavenTransfersLogFlag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
def mavenGoals = configuration.goals
|
|
|
|
if (mavenGoals?.trim()) {
|
|
|
|
command += " ${mavenGoals}"
|
|
|
|
}
|
|
|
|
def defines = configuration.defines
|
|
|
|
if (defines?.trim()){
|
|
|
|
command += " ${defines}"
|
|
|
|
}
|
2018-08-21 15:45:59 +02:00
|
|
|
dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) {
|
|
|
|
sh command
|
|
|
|
}
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private downloadSettingsFromUrl(String url){
|
2018-02-15 16:50:07 +02:00
|
|
|
def settings = httpRequest url
|
|
|
|
writeFile file: 'settings.xml', text: settings.getContent()
|
2017-12-06 13:03:06 +02:00
|
|
|
}
|
|
|
|
|