1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/vars/newmanExecute.groovy
lndrschlz dea96a3ba0
feat(newmanExecute): golang implmementation for newmanExecute (#2513)
* Automates first parts of newmanExecute.groovy

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds newman installation

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Removes warning

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* makes tests robust for later shell calls

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds version logging

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds tests for version logging

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds newman shell execution

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Prepare cloud foundry apps with secrets handling

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds further process to CF Utils

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Fixes unit test

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adds error category

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Add fix to execute step locally

Currently only tested on windows machine locally in powershell.

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* Adapt unit test to fix of runCommand

Signed-off-by: Fabian Reh <fabian.reh@sap.com>

* refactored golang step to newmanExecute

* wip

* added test config

* refactored newmanExecute groovy wrapper step

* exclude newmanExecute from common step test

* cleaups

* add credential support

* fix groovy credential providing

* add import

* add stageName

* define script

* remove unused vars

* add import

* fix iterator ref

* golang secret handling and cleanups

* wip

* wip

* wip

* update go step

* implement cf credential proposal

* testRepository functionality implemented

* register secrets to logger

* add missing dependecies

* test xsuaa credential handling

* wip

* wip

* cleanups

* add import

* remove mandatory params

* add container definition

* test runCommand

* test runCommand

* fix npm path

* fix npm path

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* added newmanEnvironment to templating

* wip

* use env and globals params in runCommand when no templating

* fix condition

* wip

* reverted config edit

* updated documentation

* install with shell

* wip

* wip

* fix tests

* refactor tests

* wip

* remove old test

* wip

* escape go tmpl

* escape go tmpl

* fix defaults

* add doc comment

* remove test case

* refactored newman commands

* add cli reporter

* refactor options

* mock os getenv and fix all tests

* refactoring and doc update

* go generate

* small refactor

* spelling

* fix newman doc

* remove MaskPasswords wrapper; fix stash bug;

* docu fix

Co-authored-by: Fabian Reh <fabian.reh@sap.com>
2021-03-17 08:08:33 +01:00

70 lines
3.3 KiB
Groovy

import com.sap.piper.ConfigurationHelper
import com.sap.piper.integration.CloudFoundry
import groovy.transform.Field
import com.sap.piper.GitUtils
import static com.sap.piper.Prerequisites.checkScript
@Field String STEP_NAME = getClass().getName()
@Field String METADATA_FILE = 'metadata/newmanExecute.yaml'
@Field Set CONFIG_KEYS = [
/**
* 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})
*/
"cfAppsWithSecrets",
/**
* Define an additional repository where the test implementation is located.
* For protected repositories the `testRepository` needs to contain the ssh git url.
*/
'testRepository',
/**
* Only if `testRepository` is provided: Branch of testRepository, defaults to master.
*/
'gitBranch',
/**
* Only if `testRepository` is provided: Credentials for a protected testRepository
* @possibleValues Jenkins credentials id
*/
'gitSshKeyCredentialsId',
]
@Field Map CONFIG_KEY_COMPATIBILITY = [cloudFoundry: [apiEndpoint: 'cfApiEndpoint', credentialsId: 'cfCredentialsId', org: 'cfOrg', space: 'cfSpace']]
void call(Map parameters = [:]) {
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()
if (parameters.testRepository || config.testRepository ) {
parameters.stashContent = [GitUtils.handleTestRepository(this, [gitBranch: config.gitBranch, gitSshKeyCredentialsId: config.gitSshKeyCredentialsId, testRepository: config.testRepository])]
}
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"
}
}
withEnv(cfCredentials) {
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, [])
}
}