2018-07-03 14:16:17 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2020-06-12 10:04:03 +02:00
|
|
|
import com.sap.piper.integration.CloudFoundry
|
2018-10-08 11:30:42 +02:00
|
|
|
import groovy.transform.Field
|
2021-03-17 09:08:33 +02:00
|
|
|
import com.sap.piper.GitUtils
|
2018-07-03 14:16:17 +02:00
|
|
|
|
2021-03-17 09:08:33 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
2018-10-25 15:44:21 +02:00
|
|
|
|
2021-03-17 09:08:33 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
|
|
|
@Field String METADATA_FILE = 'metadata/newmanExecute.yaml'
|
2018-10-25 15:44:21 +02:00
|
|
|
|
2021-03-17 09:08:33 +02:00
|
|
|
@Field Set CONFIG_KEYS = [
|
2018-12-10 12:53:48 +02:00
|
|
|
/**
|
2021-03-17 09:08:33 +02:00
|
|
|
* Define name array of cloud foundry apps deployed for which secrets (clientid and clientsecret) will be appended
|
|
|
|
* to the newman command that overrides the environment json entries
|
|
|
|
* (--env-var <appName_clientid>=${clientid} & --env-var <appName_clientsecret>=${clientsecret})
|
2019-03-26 14:26:21 +02:00
|
|
|
*/
|
2021-03-17 09:08:33 +02:00
|
|
|
"cfAppsWithSecrets",
|
2018-12-10 12:53:48 +02:00
|
|
|
/**
|
2019-03-26 14:26:21 +02:00
|
|
|
* Define an additional repository where the test implementation is located.
|
|
|
|
* For protected repositories the `testRepository` needs to contain the ssh git url.
|
|
|
|
*/
|
2020-06-12 10:04:03 +02:00
|
|
|
'testRepository',
|
|
|
|
/**
|
2021-03-17 09:08:33 +02:00
|
|
|
* Only if `testRepository` is provided: Branch of testRepository, defaults to master.
|
2020-06-12 10:04:03 +02:00
|
|
|
*/
|
2021-03-17 09:08:33 +02:00
|
|
|
'gitBranch',
|
2020-06-12 10:04:03 +02:00
|
|
|
/**
|
2021-03-17 09:08:33 +02:00
|
|
|
* Only if `testRepository` is provided: Credentials for a protected testRepository
|
|
|
|
* @possibleValues Jenkins credentials id
|
2020-06-12 10:04:03 +02:00
|
|
|
*/
|
2021-03-17 09:08:33 +02:00
|
|
|
'gitSshKeyCredentialsId',
|
2018-07-04 11:12:32 +02:00
|
|
|
]
|
2018-10-25 15:44:21 +02:00
|
|
|
|
2020-06-12 10:04:03 +02:00
|
|
|
@Field Map CONFIG_KEY_COMPATIBILITY = [cloudFoundry: [apiEndpoint: 'cfApiEndpoint', credentialsId: 'cfCredentialsId', org: 'cfOrg', space: 'cfSpace']]
|
|
|
|
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2021-03-17 09:08:33 +02:00
|
|
|
final script = checkScript(this, parameters) ?: this
|
|
|
|
String stageName = parameters.stageName ?: env.STAGE_NAME
|
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults([:], stageName)
|
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, stageName, CONFIG_KEYS)
|
|
|
|
.mixin(parameters, CONFIG_KEYS, CONFIG_KEY_COMPATIBILITY)
|
|
|
|
.use()
|
2018-07-03 14:16:17 +02:00
|
|
|
|
2021-03-17 09:08:33 +02:00
|
|
|
if (parameters.testRepository || config.testRepository ) {
|
|
|
|
parameters.stashContent = [GitUtils.handleTestRepository(this, [gitBranch: config.gitBranch, gitSshKeyCredentialsId: config.gitSshKeyCredentialsId, testRepository: config.testRepository])]
|
|
|
|
}
|
2020-06-12 10:04:03 +02:00
|
|
|
|
2021-03-17 09:08:33 +02:00
|
|
|
List<String> cfCredentials = []
|
|
|
|
if (config.cfAppsWithSecrets) {
|
|
|
|
CloudFoundry cfUtils = new CloudFoundry(script);
|
|
|
|
config.cfAppsWithSecrets.each { appName ->
|
|
|
|
def xsuaaCredentials = cfUtils.getXsuaaCredentials(config.cloudFoundry.apiEndpoint,
|
|
|
|
config.cloudFoundry.org,
|
|
|
|
config.cloudFoundry.space,
|
|
|
|
config.cloudFoundry.credentialsId,
|
|
|
|
appName,
|
|
|
|
config.verbose ? true : false )
|
|
|
|
cfCredentials.add("PIPER_NEWMANEXECUTE_${appName}_clientid=${xsuaaCredentials.clientid}")
|
|
|
|
cfCredentials.add("PIPER_NEWMANEXECUTE_${appName}_clientsecret=${xsuaaCredentials.clientsecret}")
|
|
|
|
echo "Exposing client id and secret for ${appName}: as ${appName}_clientid and ${appName}_clientsecret to newmanExecute"
|
2018-07-03 14:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-17 09:08:33 +02:00
|
|
|
withEnv(cfCredentials) {
|
|
|
|
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, [])
|
|
|
|
}
|
2018-07-03 14:16:17 +02:00
|
|
|
}
|