-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathDeclarativePipelineTest.groovy
More file actions
51 lines (44 loc) · 1.91 KB
/
DeclarativePipelineTest.groovy
File metadata and controls
51 lines (44 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.lesfurets.jenkins.unit.declarative
import com.lesfurets.jenkins.unit.BasePipelineTest
import static com.lesfurets.jenkins.unit.MethodSignature.method
@groovy.transform.InheritConstructors
abstract class DeclarativePipelineTest extends BasePipelineTest {
def pipelineInterceptor = { Closure closure ->
GenericPipelineDeclaration.binding = binding
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 paremetes { string(...)}
if (desc.name) {
addParam(desc.name, desc.defaultValue, false)
}
// we are in context of withCredentaials([string()..]) { }
if(desc.variable) {
return desc.variable
}
}
}
@Override
void setUp() throws Exception {
super.setUp()
helper.registerAllowedMethod('booleanParam', [Map], paramInterceptor)
helper.registerAllowedMethod('checkout', [Closure])
helper.registerAllowedMethod('credentials', [String], { String credName ->
return binding.getVariable('credentials')[credName]
})
helper.registerAllowedMethod('cron', [String])
helper.registerAllowedMethod(method("pipeline", Closure), pipelineInterceptor)
helper.registerAllowedMethod('pollSCM', [String])
helper.registerAllowedMethod('script', [Closure])
helper.registerAllowedMethod('skipDefaultCheckout')
helper.registerAllowedMethod('string', [Map], stringInterceptor)
helper.registerAllowedMethod('timeout', [Integer, Closure])
helper.registerAllowedMethod('timestamps')
binding.setVariable('credentials', [:])
binding.setVariable('params', [:])
}
}