github.com/jaylevin/jenkins-library@v1.230.4/vars/dubExecute.groovy (about) 1 import static com.sap.piper.Prerequisites.checkScript 2 import com.sap.piper.GenerateDocumentation 3 import com.sap.piper.ConfigurationHelper 4 import com.sap.piper.Utils 5 import groovy.transform.Field 6 7 @Field def STEP_NAME = getClass().getName() 8 @Field Set GENERAL_CONFIG_KEYS = [] 9 @Field Set STEP_CONFIG_KEYS = [ 10 /** 11 * Name of the docker image that should be used, in which node should be installed and configured. Default value is 'dlang2/dmd-ubuntu:latest'. 12 */ 13 'dockerImage', 14 /** @see dockerExecute*/ 15 'dockerEnvVars', 16 /** @see dockerExecute */ 17 'dockerOptions', 18 /** @see dockerExecute*/ 19 'dockerWorkspace', 20 /** 21 * URL of default DUB registry 22 */ 23 'defaultDubRegistry', 24 /** 25 * Which DUB command should be executed. 26 */ 27 'dubCommand'] 28 @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS + [ 29 /** 30 * Docker options to be set when starting the container. 31 */ 32 'dockerOptions'] 33 /** 34 * Executes DUB commands inside a docker container. 35 * Docker image, docker options and dub commands can be specified or configured. 36 */ 37 @GenerateDocumentation 38 void call(Map parameters = [:], body = null) { 39 handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) { 40 41 final script = checkScript(this, parameters) ?: this 42 String stageName = parameters.stageName ?: env.STAGE_NAME 43 44 // load default & individual configuration 45 Map configuration = ConfigurationHelper.newInstance(this) 46 .loadStepDefaults([:], stageName) 47 .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS) 48 .mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS) 49 .mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS) 50 .mixin(parameters, PARAMETER_KEYS) 51 .use() 52 53 new Utils().pushToSWA([ 54 step: STEP_NAME, 55 stepParamKey1: 'scriptMissing', 56 stepParam1: parameters?.script == null 57 ], configuration) 58 59 if (!fileExists('dub.json') && !fileExists('dub.sdl')) { 60 error "[${STEP_NAME}] Neither dub.json nor dub.sdl was found." 61 } 62 dockerExecute(script: script, 63 dockerImage: configuration.dockerImage, 64 dockerEnvVars: configuration.dockerEnvVars, 65 dockerOptions: configuration.dockerOptions, 66 dockerWorkspace: configuration.dockerWorkspace 67 ) { 68 if (configuration.defaultDubRegistry) { 69 sh """ 70 mkdir ~/.dub 71 echo '{"skipRegistry": "standard", "registryUrls": ["${configuration.defaultDubRegistry}"]}' > ~/.dub/settings.json 72 """ 73 } 74 if (configuration.dubCommand) { 75 sh "dub ${configuration.dubCommand}" 76 } 77 if (body) { 78 body() 79 } 80 } 81 } 82 }