1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-04-17 12:06:28 +02:00

Enables skipping the checkout in piperPipelineInitStage step by providing stashes (#3085)

* enable unstashing for initial content

* syntax fix

* beatufy unstashing

* Apply suggestions from code review

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

* fix tests

* fix tests

* avoid npe

* Fix syntax

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

* Update vars/piperPipelineStageInit.groovy

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* add unit tests

* Update vars/piperPipelineStageInit.groovy

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>
Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
This commit is contained in:
Thorsten Duda 2021-09-08 08:13:32 +02:00 committed by GitHub
parent e7fbd1c112
commit 6c339b8aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -237,6 +237,7 @@ class PiperPipelineStageInitTest extends BasePiperTest {
buildTool: 'maven',
stashSettings: 'com.sap.piper/pipeline/stashSettings.yml',
skipCheckout: true,
stashContent: ['mystash'],
scmInfo: ["dummyScmKey":"dummyScmKey"]
)
@ -270,8 +271,37 @@ class PiperPipelineStageInitTest extends BasePiperTest {
juStabUtils: utils,
buildTool: 'maven',
stashSettings: 'com.sap.piper/pipeline/stashSettings.yml',
stashContent: ['mystash'],
skipCheckout: true
)
}
@Test
void "Try to skip checkout without stashContent parameter throws error"() {
thrown.expectMessage('[piperPipelineStageInit] needs stashes if you skip checkout')
jsr.step.piperPipelineStageInit(
script: nullScript,
juStabUtils: utils,
buildTool: 'maven',
stashSettings: 'com.sap.piper/pipeline/stashSettings.yml',
skipCheckout: true,
scmInfo: ["dummyScmKey":"dummyScmKey"]
)
}
@Test
void "Try to skip checkout with empty stashContent parameter throws error"() {
thrown.expectMessage('[piperPipelineStageInit] needs stashes if you skip checkout')
jsr.step.piperPipelineStageInit(
script: nullScript,
juStabUtils: utils,
buildTool: 'maven',
stashSettings: 'com.sap.piper/pipeline/stashSettings.yml',
skipCheckout: true,
stashContent: [],
scmInfo: ["dummyScmKey":"dummyScmKey"]
)
}
}

View File

@ -84,6 +84,10 @@ import static com.sap.piper.Prerequisites.checkScript
* @possibleValues `true`, `false`
*/
'skipCheckout',
/**
* Mandatory if you skip the checkout. Then you need to unstash your workspace to get the e.g. configuration.
*/
'stashContent',
/**
* Optional path to the pipeline configuration file defining project specific settings.
*/
@ -136,6 +140,13 @@ void call(Map parameters = [:]) {
if (!skipCheckout) {
scmInfo = checkout(parameters.checkoutMap ?: scm)
}
else {
def stashContent = parameters.stashContent
if(stashContent == null || stashContent.size() == 0) {
error "[${STEP_NAME}] needs stashes if you skip checkout"
}
utils.unstashAll(stashContent)
}
setupCommonPipelineEnvironment(script: script, customDefaults: parameters.customDefaults, scmInfo: scmInfo,
configFile: parameters.configFile, customDefaultsFromFiles: parameters.customDefaultsFromFiles)