1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/vars/cloudFoundryDeploy.groovy
Marcus Holl cf62c35b1a
Fix env var replacement (#3260)
* Fix envVar replacement (go part)

* Fix envVar replacement (groovy part)

* insert underscore also after 0-9 (go part)

* insert underscore also after 0-9 (groovy part)

* Adjust tests for trailing numbers

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-11-15 12:59:49 +01:00

40 lines
1.8 KiB
Groovy

import com.sap.piper.Utils
import groovy.transform.Field
import static com.sap.piper.Prerequisites.checkScript
@Field String STEP_NAME = getClass().getName()
@Field String METADATA_FILE = 'metadata/cloudFoundryDeploy.yaml'
void call(Map parameters = [:]) {
final script = checkScript(this, parameters) ?: this
String stageName = parameters.stageName ?: env.STAGE_NAME
def utils = parameters.juStabUtils ?: new Utils()
utils.unstashAll(["deployDescriptor"])
List credentials = [
[type: 'usernamePassword', id: 'cfCredentialsId', env: ['PIPER_username', 'PIPER_password']],
[type: 'usernamePassword', id: 'dockerCredentialsId', env: ['PIPER_dockerUsername', 'PIPER_dockerPassword']]
]
Map mtaExtensionCredentials = parameters.mtaExtensionCredentials ?: script.commonPipelineEnvironment.getStepConfiguration(STEP_NAME, stageName).mtaExtensionCredentials
if (mtaExtensionCredentials) {
mtaExtensionCredentials.each { key, credentialsId ->
echo "[INFO]${STEP_NAME}] Preparing credential for being used by piper-go. key: ${key}, credentialsId is: ${credentialsId}, exposed as environment variable ${toEnvVarKey(credentialsId)}"
credentials << [type: 'token', id: credentialsId, env: [toEnvVarKey(credentialsId)], resolveCredentialsId: false]
}
}
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
}
/*
* Inserts underscores before all upper case letters which are not already
* have an underscore before, replaces any non letters/digits with underscore
* and transforms all lower case letters to upper case.
*/
private static String toEnvVarKey(String key) {
key = key.replaceAll(/[^A-Za-z0-9]/, "_")
key = key.replaceAll(/([a-z0-9])([A-Z])/, /$1_$2/)
return key.toUpperCase()
}