github.com/xgoffin/jenkins-library@v1.154.0/vars/newmanExecute.groovy (about)

     1  import com.sap.piper.ConfigurationHelper
     2  import com.sap.piper.integration.CloudFoundry
     3  import groovy.transform.Field
     4  import com.sap.piper.GitUtils
     5  
     6  import static com.sap.piper.Prerequisites.checkScript
     7  
     8  @Field String STEP_NAME = getClass().getName()
     9  @Field String METADATA_FILE = 'metadata/newmanExecute.yaml'
    10  
    11  @Field Set CONFIG_KEYS = [
    12      /**
    13       * Define name array of cloud foundry apps deployed for which secrets (clientid and clientsecret) will be appended
    14       * to the newman command that overrides the environment json entries
    15       * (--env-var <appName_clientid>=${clientid} & --env-var <appName_clientsecret>=${clientsecret})
    16       */
    17      "cfAppsWithSecrets",
    18      /**
    19       * Define an additional repository where the test implementation is located.
    20       * For protected repositories the `testRepository` needs to contain the ssh git url.
    21       */
    22      'testRepository',
    23      /**
    24       * Only if `testRepository` is provided: Branch of testRepository, defaults to master.
    25       */
    26      'gitBranch',
    27      /**
    28       * Only if `testRepository` is provided: Credentials for a protected testRepository
    29       * @possibleValues Jenkins credentials id
    30       */
    31      'gitSshKeyCredentialsId',
    32  ]
    33  
    34  @Field Map CONFIG_KEY_COMPATIBILITY = [cloudFoundry: [apiEndpoint: 'cfApiEndpoint', credentialsId: 'cfCredentialsId', org: 'cfOrg', space: 'cfSpace']]
    35  
    36  void call(Map parameters = [:]) {
    37      final script = checkScript(this, parameters) ?: this
    38      String stageName = parameters.stageName ?: env.STAGE_NAME
    39      Map config = ConfigurationHelper.newInstance(this)
    40          .loadStepDefaults([:], stageName)
    41          .mixinGeneralConfig(script.commonPipelineEnvironment, CONFIG_KEYS)
    42          .mixinStepConfig(script.commonPipelineEnvironment, CONFIG_KEYS)
    43          .mixinStageConfig(script.commonPipelineEnvironment, stageName, CONFIG_KEYS)
    44          .mixin(parameters, CONFIG_KEYS, CONFIG_KEY_COMPATIBILITY)
    45          .use()
    46  
    47      if (parameters.testRepository || config.testRepository ) {
    48          parameters.stashContent = [GitUtils.handleTestRepository(this, [gitBranch: config.gitBranch, gitSshKeyCredentialsId: config.gitSshKeyCredentialsId, testRepository: config.testRepository])]
    49      }
    50  
    51      List<String> cfCredentials = []
    52      if (config.cfAppsWithSecrets) {
    53          CloudFoundry cfUtils = new CloudFoundry(script);
    54          config.cfAppsWithSecrets.each { appName ->
    55              def xsuaaCredentials = cfUtils.getXsuaaCredentials(config.cloudFoundry.apiEndpoint,
    56                                                              config.cloudFoundry.org,
    57                                                              config.cloudFoundry.space,
    58                                                              config.cloudFoundry.credentialsId,
    59                                                              appName,
    60                                                              config.verbose ? true : false )
    61              cfCredentials.add("PIPER_NEWMANEXECUTE_${appName}_clientid=${xsuaaCredentials.clientid}")
    62              cfCredentials.add("PIPER_NEWMANEXECUTE_${appName}_clientsecret=${xsuaaCredentials.clientsecret}")
    63              echo "Exposing client id and secret for ${appName}: as ${appName}_clientid and ${appName}_clientsecret to newmanExecute"
    64          }
    65      }
    66      withEnv(cfCredentials) {
    67          piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, [])
    68      }
    69  }