2018-07-30 09:28:24 +02:00
import com.sap.piper.Utils
import groovy.transform.Field
2020-02-25 11:20:15 +02:00
import static com . sap . piper . Prerequisites . checkScript
2018-11-29 10:54:05 +02:00
@Field String STEP_NAME = getClass ( ) . getName ( )
2021-11-09 08:44:31 +02:00
@Field String METADATA_FILE = 'metadata/cloudFoundryDeploy.yaml'
2018-10-25 14:24:17 +02:00
2018-08-30 16:33:07 +02:00
void call ( Map parameters = [ : ] ) {
2021-11-09 08:44:31 +02:00
final script = checkScript ( this , parameters ) ? : this
String stageName = parameters . stageName ? : env . STAGE_NAME
2018-07-30 09:28:24 +02:00
2021-11-09 08:44:31 +02:00
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' ] ]
]
2021-01-12 10:17:34 +02:00
2021-11-09 08:44:31 +02:00
Map mtaExtensionCredentials = parameters . mtaExtensionCredentials ? : script . commonPipelineEnvironment . getStepConfiguration ( STEP_NAME , stageName ) . mtaExtensionCredentials
2018-07-30 09:28:24 +02:00
2021-11-09 08:44:31 +02:00
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 ]
2020-07-06 11:45:36 +02:00
}
2018-07-30 09:28:24 +02:00
}
2021-11-09 08:44:31 +02:00
piperExecuteBin ( parameters , STEP_NAME , METADATA_FILE , credentials )
2018-07-30 09:28:24 +02:00
}
2021-01-12 10:17:34 +02:00
/ *
* 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]/ , "_" )
2021-11-15 13:59:49 +02:00
key = key . replaceAll ( /([a-z0-9])([A-Z])/ , /$1_$2/ )
2021-01-12 10:17:34 +02:00
return key . toUpperCase ( )
}