mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Add ability to load custom defaults from secured resource (#1680)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
This commit is contained in:
parent
f7015b562d
commit
6dfd83d246
@ -11,7 +11,10 @@ import groovy.transform.Field
|
||||
|
||||
@Field Set GENERAL_CONFIG_KEYS = [
|
||||
/** */
|
||||
'collectTelemetryData'
|
||||
'collectTelemetryData',
|
||||
|
||||
/** Credentials (username and password) used to download custom defaults if access is secured.*/
|
||||
'customDefaultsCredentialsId'
|
||||
]
|
||||
|
||||
@Field Set STEP_CONFIG_KEYS = []
|
||||
@ -69,7 +72,8 @@ void call(Map parameters = [:]) {
|
||||
customDefaultsFiles = Utils.appendParameterToStringList(
|
||||
customDefaultsFiles, script.commonPipelineEnvironment.configuration as Map, 'customDefaults')
|
||||
}
|
||||
customDefaultsFiles = copyOrDownloadCustomDefaultsIntoPipelineEnv(script, customDefaultsFiles)
|
||||
String customDefaultsCredentialsId = script.commonPipelineEnvironment.configuration.general?.customDefaultsCredentialsId
|
||||
customDefaultsFiles = copyOrDownloadCustomDefaultsIntoPipelineEnv(script, customDefaultsFiles, customDefaultsCredentialsId)
|
||||
|
||||
prepareDefaultValues([
|
||||
script: script,
|
||||
@ -112,7 +116,7 @@ private static loadConfigurationFromFile(script, String configFile) {
|
||||
}
|
||||
}
|
||||
|
||||
private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List customDefaults) {
|
||||
private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List customDefaults, String credentialsId) {
|
||||
List fileList = []
|
||||
int urlCount = 0
|
||||
for (int i = 0; i < customDefaults.size(); i++) {
|
||||
@ -125,10 +129,14 @@ private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List cus
|
||||
if (customDefaults[i].startsWith('http://') || customDefaults[i].startsWith('https://')) {
|
||||
fileName = "custom_default_from_url_${urlCount}.yml"
|
||||
|
||||
def response = script.httpRequest(
|
||||
Map httpRequestParameters = [
|
||||
url: customDefaults[i],
|
||||
validResponseCodes: '100:399,404' // Allow a more specific error message for 404 case
|
||||
)
|
||||
]
|
||||
if (credentialsId) {
|
||||
httpRequestParameters.authentication = credentialsId
|
||||
}
|
||||
def response = script.httpRequest(httpRequestParameters)
|
||||
if (response.status == 404) {
|
||||
error "URL for remote custom defaults (${customDefaults[i]}) appears to be incorrect. " +
|
||||
"Server returned HTTP status code 404. " +
|
||||
|
Loading…
Reference in New Issue
Block a user