1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/vars/cloudFoundryDeploy.groovy
Oliver Nocon b4d314215e
chore(cloudFoundryDeploy): remove deprecated groovy-based part (#3242)
* chore(cloudFoundryDeploy): remove deprecated groovy-based part

* chore: update test due to different step logic

* chore: update documentation

* fix yaml issue
2021-11-09 07:44:31 +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-Z])/, "\$1_\$2")
return key.toUpperCase()
}