mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-04 04:07:16 +02:00
Pass custom default-config files and custom project config from Jenkins side to piper (#1333)
This commit is contained in:
parent
0c3493f9ad
commit
03096b5d05
@ -126,7 +126,12 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
|
||||
var defaultConfig []io.ReadCloser
|
||||
for _, f := range GeneralConfig.DefaultConfig {
|
||||
//ToDo: support also https as source
|
||||
fc, _ := openFile(f)
|
||||
fc, err := openFile(f)
|
||||
if err != nil {
|
||||
log.Entry().Infof("Failed to add default config '%s': %v", f, err)
|
||||
} else {
|
||||
log.Entry().Infof("Added default config '%s'", f)
|
||||
}
|
||||
defaultConfig = append(defaultConfig, fc)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,9 @@ class commonPipelineEnvironment implements Serializable {
|
||||
Map configuration = [:]
|
||||
Map containerProperties = [:]
|
||||
Map defaultConfiguration = [:]
|
||||
|
||||
// Location of the file from where the configuration was parsed. See setupCommonPipelineEnvironment.groovy
|
||||
// Useful for making sure that the piper binary uses the same file when called from Jenkins.
|
||||
String configurationFile = ''
|
||||
|
||||
String mtarFilePath
|
||||
private Map valueMap = [:]
|
||||
|
@ -1,3 +1,5 @@
|
||||
import com.sap.piper.BashUtils
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import com.sap.piper.JenkinsUtils
|
||||
import com.sap.piper.PiperGoUtils
|
||||
import com.sap.piper.Utils
|
||||
@ -35,7 +37,7 @@ void call(Map parameters = [:], stepName, metadataFile, List credentialInfo, fai
|
||||
|
||||
dockerWrapper(script, config) {
|
||||
credentialWrapper(config, credentialInfo) {
|
||||
sh "./piper ${stepName}"
|
||||
sh "./piper ${stepName}${getCustomDefaultConfigsArg()}${getCustomConfigArg(script)}"
|
||||
}
|
||||
jenkinsUtils.handleStepResults(stepName, failOnMissingReports, failOnMissingLinks)
|
||||
}
|
||||
@ -43,6 +45,32 @@ void call(Map parameters = [:], stepName, metadataFile, List credentialInfo, fai
|
||||
}
|
||||
}
|
||||
|
||||
static String getCustomDefaultConfigs() {
|
||||
// The default config files were extracted from merged library
|
||||
// resources by setupCommonPipelineEnvironment.groovy into .pipeline/.
|
||||
List customDefaults = DefaultValueCache.getInstance().getCustomDefaults()
|
||||
for (int i = 0; i < customDefaults.size(); i++) {
|
||||
customDefaults[i] = BashUtils.quoteAndEscape(".pipeline/${customDefaults[i]}")
|
||||
}
|
||||
return customDefaults.join(',')
|
||||
}
|
||||
|
||||
static String getCustomDefaultConfigsArg() {
|
||||
String customDefaults = getCustomDefaultConfigs()
|
||||
if (customDefaults) {
|
||||
return " --defaultConfig ${customDefaults}"
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
static String getCustomConfigArg(def script) {
|
||||
if (script?.commonPipelineEnvironment?.configurationFile
|
||||
&& script.commonPipelineEnvironment.configurationFile != '.pipeline/config.yaml') {
|
||||
return " --customConfig ${BashUtils.quoteAndEscape(script.commonPipelineEnvironment.configurationFile)}"
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
void dockerWrapper(script, config, body) {
|
||||
if (config.dockerImage) {
|
||||
dockerExecute(
|
||||
|
@ -64,15 +64,19 @@ void call(Map parameters = [:]) {
|
||||
}
|
||||
|
||||
private loadConfigurationFromFile(script, String configFile) {
|
||||
if (!configFile) {
|
||||
String defaultYmlConfigFile = '.pipeline/config.yml'
|
||||
String defaultYamlConfigFile = '.pipeline/config.yaml'
|
||||
if (fileExists(defaultYmlConfigFile)) {
|
||||
configFile = defaultYmlConfigFile
|
||||
} else if (fileExists(defaultYamlConfigFile)) {
|
||||
configFile = defaultYamlConfigFile
|
||||
}
|
||||
}
|
||||
|
||||
String defaultYmlConfigFile = '.pipeline/config.yml'
|
||||
String defaultYamlConfigFile = '.pipeline/config.yaml'
|
||||
|
||||
// A file passed to the function is not checked for existence in order to fail the pipeline.
|
||||
if (configFile) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: configFile)
|
||||
} else if (fileExists(defaultYmlConfigFile)) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: defaultYmlConfigFile)
|
||||
} else if (fileExists(defaultYamlConfigFile)) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: defaultYamlConfigFile)
|
||||
script.commonPipelineEnvironment.configurationFile = configFile
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user