1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/vars/pipelineStashFilesBeforeBuild.groovy

60 lines
2.3 KiB
Groovy
Raw Normal View History

import static com.sap.piper.Prerequisites.checkScript
2019-04-02 10:13:27 +02:00
import com.sap.piper.GenerateDocumentation
2018-05-30 12:00:13 +02:00
import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper
import groovy.transform.Field
@Field String STEP_NAME = getClass().getName()
2019-04-02 10:13:27 +02:00
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = [
/**
* By default certain files are excluded from stashing (e.g. `.git` folder).
* 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).
* This parameter allows to provide a list of stash names for which the standard exclude behavior should be switched off.
* This will allow you to also stash directories like `.git`.
*/
'noDefaultExludes',
/** @see pipelineStashFiles */
'stashIncludes',
/** @see pipelineStashFiles */
'stashExcludes'
]
2018-05-30 12:00:13 +02:00
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
2019-04-02 10:13:27 +02:00
/**
* This step stashes files that are needed in other build steps (on other nodes).
*/
@GenerateDocumentation
2018-08-30 16:33:07 +02:00
void call(Map parameters = [:]) {
2018-05-30 12:00:13 +02:00
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, stepNameDoc: 'stashFiles') {
def script = checkScript(this, parameters) ?: this
Utils utils = parameters.juStabUtils ?: new Utils()
String stageName = parameters.stageName ?: env.STAGE_NAME
2018-05-30 12:00:13 +02:00
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults([:], stageName)
2018-05-30 12:00:13 +02:00
.mixinGeneralConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
2018-05-30 12:00:13 +02:00
.mixin(parameters, PARAMETER_KEYS)
.use()
utils.pushToSWA([
step: STEP_NAME,
stepParamKey1: 'scriptMissing',
stepParam1: parameters?.script == null
], config)
config.stashIncludes.each {stashKey, stashIncludes ->
def useDefaultExcludes = !config.noDefaultExludes.contains(stashKey)
utils.stashWithMessage(stashKey, "[${STEP_NAME}] no files detected for stash '${stashKey}': ", stashIncludes, config.stashExcludes[stashKey]?:'', useDefaultExcludes)
2018-05-30 12:00:13 +02:00
}
}
}