diff --git a/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy b/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy index 3b1a5e30..88e9232c 100644 --- a/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy +++ b/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy @@ -23,7 +23,22 @@ abstract class BasePipelineTest { ClassLoader baseClassLoader = this.class.classLoader - def stringInterceptor = { m -> m.variable } + def paramInterceptor = { Map desc -> + addParam(desc.name, desc.defaultValue, false) + } + + def stringInterceptor = { Map desc-> + if (desc) { + // we are in context of parameters { string(...)} + if (desc.name) { + addParam(desc.name, desc.defaultValue, false) + } + // we are in context of withCredentials([string()..]) { } + if(desc.variable) { + return desc.variable + } + } + } def usernamePasswordInterceptor = { m -> [m.usernameVariable, m.passwordVariable] } @@ -131,6 +146,7 @@ abstract class BasePipelineTest { getProjectName:{"some_job"}, ] }) + helper.registerAllowedMethod('booleanParam', [Map], paramInterceptor) helper.registerAllowedMethod("buildDiscarder", [Object]) helper.registerAllowedMethod("checkout", [Map]) helper.registerAllowedMethod("choice", [Map]) diff --git a/src/main/groovy/com/lesfurets/jenkins/unit/declarative/DeclarativePipelineTest.groovy b/src/main/groovy/com/lesfurets/jenkins/unit/declarative/DeclarativePipelineTest.groovy index e4095ccc..640cc6d8 100644 --- a/src/main/groovy/com/lesfurets/jenkins/unit/declarative/DeclarativePipelineTest.groovy +++ b/src/main/groovy/com/lesfurets/jenkins/unit/declarative/DeclarativePipelineTest.groovy @@ -12,23 +12,6 @@ abstract class DeclarativePipelineTest extends BasePipelineTest { GenericPipelineDeclaration.createComponent(DeclarativePipeline, closure).execute(delegate) } - def paramInterceptor = { Map desc -> - addParam(desc.name, desc.defaultValue, false) - } - - def stringInterceptor = { Map desc-> - if (desc) { - // we are in context of parameters { string(...)} - if (desc.name) { - addParam(desc.name, desc.defaultValue, false) - } - // we are in context of withCredentials([string()..]) { } - if(desc.variable) { - return desc.variable - } - } - } - @Override void setUp() throws Exception { super.setUp()