github.com/jaylevin/jenkins-library@v1.230.4/vars/pipelineStashFilesAfterBuild.groovy (about) 1 import static com.sap.piper.Prerequisites.checkScript 2 3 import com.sap.piper.GenerateDocumentation 4 import com.sap.piper.Utils 5 import com.sap.piper.ConfigurationHelper 6 import groovy.transform.Field 7 8 @Field String STEP_NAME = getClass().getName() 9 10 @Field Set GENERAL_CONFIG_KEYS = [] 11 12 @Field Set STEP_CONFIG_KEYS = [ 13 /** 14 * By default certain files are excluded from stashing (e.g. `.git` folder). 15 * Details can be found as per [Pipeline basic step `stash](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#stash-stash-some-files-to-be-used-later-in-the-build). 16 * This parameter allows to provide a list of stash names for which the standard exclude behavior should be switched off. 17 * This will allow you to also stash directories like `.git`. 18 */ 19 'noDefaultExludes', 20 /** @see pipelineStashFiles */ 21 'stashIncludes', 22 /** @see pipelineStashFiles */ 23 'stashExcludes' 24 ] 25 26 @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS 27 28 /** 29 * This step stashes files that are needed in other build steps (on other nodes). 30 */ 31 @GenerateDocumentation 32 void call(Map parameters = [:]) { 33 34 handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, stepNameDoc: 'stashFiles') { 35 def script = checkScript(this, parameters) ?: this 36 def utils = parameters.juStabUtils ?: new Utils() 37 String stageName = parameters.stageName ?: env.STAGE_NAME 38 39 //additional includes via passing e.g. stashIncludes: [opa5: '**/*.include'] 40 //additional excludes via passing e.g. stashExcludes: [opa5: '**/*.exclude'] 41 42 Map config = ConfigurationHelper.newInstance(this) 43 .loadStepDefaults([:], stageName) 44 .mixinGeneralConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS) 45 .mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS) 46 .mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS) 47 .mixin(parameters, PARAMETER_KEYS) 48 .use() 49 50 utils.pushToSWA([ 51 step: STEP_NAME, 52 stepParamKey1: 'scriptMissing', 53 stepParam1: parameters?.script == null 54 ], config) 55 56 config.stashIncludes.each {stashKey, stashIncludes -> 57 def useDefaultExcludes = !config.noDefaultExludes.contains(stashKey) 58 utils.stashWithMessage(stashKey, "[${STEP_NAME}] no files detected for stash '${stashKey}': ", stashIncludes, config.stashExcludes[stashKey]?:'', useDefaultExcludes) 59 } 60 } 61 }