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

60 lines
2.2 KiB
Groovy
Raw Normal View History

import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper
import com.sap.piper.Utils
import groovy.transform.Field
@Field String STEP_NAME = 'setupCommonPipelineEnvironment'
@Field Set GENERAL_CONFIG_KEYS = ['collectTelemetryData']
2018-08-30 16:33:07 +02:00
void call(Map parameters = [:]) {
2017-07-11 15:12:03 +02:00
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
2017-07-11 15:12:03 +02:00
def script = checkScript(this, parameters)
2017-07-11 15:12:03 +02:00
2018-06-20 10:51:48 +02:00
prepareDefaultValues script: script, customDefaults: parameters.customDefaults
String configFile = parameters.get('configFile')
loadConfigurationFromFile(script, configFile)
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.use()
(parameters.utils ?: new Utils())
.pushToSWA([step: STEP_NAME, stepParam4: parameters.customDefaults?'true':'false',
stepParam5: Boolean.toString( ! (script?.commonPipelineEnvironment?.getConfigProperties() ?: [:]).isEmpty())], config)
}
}
private boolean isYaml(String fileName) {
return fileName.endsWith(".yml") || fileName.endsWith(".yaml")
}
private boolean isProperties(String fileName) {
return fileName.endsWith(".properties")
}
private loadConfigurationFromFile(script, String configFile) {
String defaultPropertiesConfigFile = '.pipeline/config.properties'
String defaultYmlConfigFile = '.pipeline/config.yml'
if (configFile?.trim()?.length() > 0 && isProperties(configFile)) {
Map configMap = readProperties(file: configFile)
script.commonPipelineEnvironment.setConfigProperties(configMap)
} else if (fileExists(defaultPropertiesConfigFile)) {
Map configMap = readProperties(file: defaultPropertiesConfigFile)
2017-07-11 15:12:03 +02:00
script.commonPipelineEnvironment.setConfigProperties(configMap)
}
2017-07-11 15:12:03 +02:00
if (configFile?.trim()?.length() > 0 && isYaml(configFile)) {
script.commonPipelineEnvironment.configuration = readYaml(file: configFile)
} else if (fileExists(defaultYmlConfigFile)) {
script.commonPipelineEnvironment.configuration = readYaml(file: defaultYmlConfigFile)
2017-07-11 15:12:03 +02:00
}
}