/
Root.groovy
110 lines (95 loc) · 3.85 KB
/
Root.groovy
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jenkinsci.plugins.pipeline.modeldefinition.model
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
/**
* Root-level configuration object for the entire model.
*
* @author Andrew Bayer
*/
@ToString
@EqualsAndHashCode
@SuppressFBWarnings(value="SE_NO_SERIALVERSIONID")
class Root implements Serializable {
Agent agent
Stages stages
PostBuild post
Environment environment
Tools tools
Options options
Triggers triggers
Parameters parameters
Libraries libraries
final String astUUID
@Whitelisted
Root(Agent agent, Stages stages, PostBuild post, Environment environment, Tools tools, Options options,
Triggers triggers, Parameters parameters, Libraries libraries, String astUUID) {
this.agent = agent
this.stages = stages
this.post = post
this.environment = environment
this.tools = tools
this.options = options
this.triggers = triggers
this.parameters = parameters
this.libraries = libraries
this.astUUID = astUUID
}
/**
* Helper method for translating the key/value pairs in the {@link Environment} into a list of "key=value" strings
* suitable for use with the withEnv step.
*
* @return a map of keys to closures.
*/
Map<String,Closure> getEnvVars(CpsScript script) {
if (environment != null) {
environment.envResolver.setScript(script)
return environment.envResolver.closureMap
} else {
return [:]
}
}
/**
* Returns true if at least one build condition for the given responder is satisfied currently.
*
* @param r an {@link AbstractBuildConditionResponder}, such as {@link PostStage} or {@link PostBuild}.
* @param runWrapperObj The {@link RunWrapper} for the build.
* @param context The context where this is being called, which could be either a {@link Root} or a {@link Stage}, but also could be null.
* @param error The first error seen in the relevant context. Can be null.
* @return True if at least one condition is satisfied, false otherwise.
*/
/*package*/ boolean hasSatisfiedConditions(AbstractBuildConditionResponder r, Object runWrapperObj, Object context = null,
Throwable error = null) {
if (r != null) {
return r.satisfiedConditions(runWrapperObj, context, error)
} else {
return false
}
}
}