1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-30 05:59:39 +02:00

Merge pull request #1122 from SAP/stashing-steps

Move stage stashing functionality into Utils
This commit is contained in:
Stephan Aßmus 2020-01-29 21:57:09 +01:00 committed by GitHub
commit 1f2ae0fcef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 15 deletions

View File

@ -61,6 +61,31 @@ def stashWithMessage(name, msg, include = '**/*.*', exclude = '', useDefaultExcl
}
}
def stashStageFiles(Script script, String stageName) {
List stashes = script.commonPipelineEnvironment.configuration.stageStashes?.get(stageName)?.stashes ?: []
stashList(script, stashes)
//NOTE: We do not delete the directory in case Jenkins runs on Kubernetes.
// deleteDir() is not required in pods, but would be nice to have the same behaviour and leave a clean fileSystem.
if (!isInsidePod(script)) {
script.deleteDir()
}
}
def unstashStageFiles(Script script, String stageName, List stashContent = []) {
stashContent += script.commonPipelineEnvironment.configuration.stageStashes?.get(stageName)?.unstash ?: []
script.deleteDir()
unstashAll(stashContent)
return stashContent
}
boolean isInsidePod(Script script) {
return script.env.POD_NAME
}
def unstash(name, msg = "Unstash failed:") {
def unstashedContent = []

View File

@ -60,11 +60,8 @@ private void executeStage(script, originalStage, stageName, config, utils) {
def startTime = System.currentTimeMillis()
try {
//Add general stage stashes to config.stashContent
config.stashContent += script.commonPipelineEnvironment.configuration.stageStashes?.get(stageName)?.unstash ?: []
deleteDir()
utils.unstashAll(config.stashContent)
// Add general stage stashes to config.stashContent
config.stashContent = utils.unstashStageFiles(script, stageName, config.stashContent)
/* Defining the sources where to look for a project extension and a repository extension.
* Files need to be named like the executed stage to be recognized.
@ -98,12 +95,7 @@ private void executeStage(script, originalStage, stageName, config, utils) {
} finally {
//Perform stashing of selected files in workspace
utils.stashList(script, script.commonPipelineEnvironment.configuration.stageStashes?.get(stageName)?.stashes ?: [])
//NOTE: We do not delete the directory in case Jenkins runs on Kubernetes.
// deleteDir() is not required in pods, but would be nice to have the same behaviour and leave a clean fileSystem.
if (!isInsidePod(script)) {
deleteDir()
}
utils.stashStageFiles(script, stageName)
def duration = System.currentTimeMillis() - startTime
utils.pushToSWA([
@ -166,7 +158,3 @@ private boolean isOldInterceptorInterfaceUsed(Script interceptor) {
MetaMethod method = interceptor.metaClass.pickMethod("call", [Closure.class, String.class, Map.class, Map.class] as Class[])
return method != null
}
private boolean isInsidePod(Script script) {
return script.env.POD_NAME
}