1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

piperStageWrapper - switch to parameter map for extensions (#424)

switch to using a parameter map
This commit is contained in:
Oliver Nocon 2019-01-14 10:25:47 +01:00 committed by GitHub
parent 3cb70a2a48
commit 4064e6ffe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 16 deletions

View File

@ -54,7 +54,7 @@ class PiperStageWrapperTest extends BasePiperTest {
@Test
void testDefault() {
def testInt = 1
def executed = false
jsr.step.piperStageWrapper(
script: nullScript,
juStabUtils: utils,
@ -62,16 +62,16 @@ class PiperStageWrapperTest extends BasePiperTest {
stageName: 'test'
) {
testInt ++
executed = true
}
assertThat(testInt, is(2))
assertThat(executed, is(true))
assertThat(lockMap.size(), is(2))
assertThat(countNodeUsage, is(1))
}
@Test
void testNoLocking() {
def testInt = 1
def executed = false
jsr.step.piperStageWrapper(
script: nullScript,
juStabUtils: utils,
@ -81,9 +81,9 @@ class PiperStageWrapperTest extends BasePiperTest {
stageName: 'test'
) {
testInt ++
executed = true
}
assertThat(testInt, is(2))
assertThat(executed, is(true))
assertThat(lockMap.size(), is(0))
assertThat(countNodeUsage, is(1))
assertThat(nodeLabel, is('testLabel'))
@ -98,21 +98,23 @@ class PiperStageWrapperTest extends BasePiperTest {
helper.registerAllowedMethod('load', [String.class], {
return helper.loadScript('test/resources/stages/test.groovy')
})
nullScript.commonPipelineEnvironment.gitBranch = 'testBranch'
def testInt = 1
def executed = false
jsr.step.piperStageWrapper(
script: nullScript,
juStabUtils: utils,
ordinal: 10,
stageName: 'test'
) {
testInt ++
executed = true
}
assertThat(testInt, is(2))
assertThat(executed, is(true))
assertThat(jlr.log, containsString('[piperStageWrapper] Running project interceptor \'.pipeline/extensions/test.groovy\' for test.'))
assertThat(jlr.log, containsString('Stage Name: test'))
assertThat(jlr.log, containsString('Config:'))
assertThat(jlr.log, containsString('Config: [productiveBranch:master,'))
assertThat(jlr.log, containsString('testBranch'))
}
}

View File

@ -1,6 +1,7 @@
void call(body, stageName, config) {
echo "Stage Name: ${stageName}"
echo "Config: ${config}"
body()
void call(Map params) {
echo "Stage Name: ${params.stageName}"
echo "Config: ${params.config}"
params.originalStage()
echo "Branch: ${params.script.commonPipelineEnvironment.gitBranch}"
}
return this

View File

@ -81,7 +81,7 @@ private void executeStage(script, originalStage, stageName, config, utils) {
echo "[${STEP_NAME}] Found global interceptor '${globalInterceptorFile}' for ${stageName}."
// If we call the global interceptor, we will pass on originalStage as parameter
body = {
globalInterceptorScript(body, stageName, config)
globalInterceptorScript(script: script, originalStage: body, stageName: stageName, config: config)
}
}
@ -90,7 +90,7 @@ private void executeStage(script, originalStage, stageName, config, utils) {
Script projectInterceptorScript = load(projectInterceptorFile)
echo "[${STEP_NAME}] Running project interceptor '${projectInterceptorFile}' for ${stageName}."
// If we call the project interceptor, we will pass on body as parameter which contains either originalStage or the repository interceptor
projectInterceptorScript(body, stageName, config)
projectInterceptorScript(script: script, originalStage: body, stageName: stageName, config: config)
} else {
//TODO: assign projectInterceptorScript to body as done for globalInterceptorScript, currently test framework does not seem to support this case. Further investigations needed.
body()