This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuildFeature.groovy
108 lines (95 loc) · 3.46 KB
/
buildFeature.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
/*-
* #%L
* pro!vision GmbH
* %%
* Copyright (C) 2018 pro!vision GmbH
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import io.wcm.devops.jenkins.pipeline.utils.TypeUtils
import io.wcm.devops.jenkins.pipeline.utils.logging.Logger
import io.wcm.devops.jenkins.pipeline.utils.maps.MapMergeMode
import io.wcm.devops.jenkins.pipeline.utils.maps.MapUtils
import org.jenkinsci.plugins.workflow.cps.DSL
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
/**
* Step for building feature branches. This step basically calls buildDefault step with custom
* maven options for the compile stage.
*
* When running in trusted mode this step also configures the appropriate scm options
* - checkout to local branch, 'LocalBranch' extension
* - merge with master, 'PreBuildMerge' extension
*
* When running in untrusted mode (folder library) the scm configuration from the job page is used for checkout.
* In this mode you have to configure
* - Checkout to local branch Extension with empty value
* - Merge before build with parent branch
*
* @param config Configuration options for the used steps
*
* @see ../vars/buildDefault.groovy
* @see ../vars/buildDefault.md
*/
void call(Map config = [:]) {
Logger log = new Logger("buildFeature")
TypeUtils typeUtils = new TypeUtils()
Map buildFeatureConfig = (Map) config[BUILD_FEATURE] ?: [:]
def _extend = typeUtils.isClosure(buildFeatureConfig[BUILD_FEATURE_EXTEND]) ? buildFeatureConfig[BUILD_FEATURE_EXTEND] : null
// no extends are configured, call the implementation
if (!_extend) {
log.debug("no extend configured, using default implementation")
_impl(config)
} else {
// call extend and provide a reference to the default implementation
_extend(config, this.&_impl)
}
}
/**
* Implementation of the step
*
* @param config Configuration options for the used steps
*/
void _impl(Map config = [:]) {
wrappers.color(config) {
Logger.init(this, config)
Logger log = new Logger(this)
Map defaultFeatureBranchConfig = [
(JOB_TYPE) : JOB_TYPE_FEATURE,
(BUILD_FEATURE): [
(STAGE_COMPILE): [
(MAVEN): [
(MAVEN_GOALS) : ["clean", "install"],
(MAP_MERGE_MODE): MapMergeMode.REPLACE
]
]
],
]
// merge with default config
config = MapUtils.merge(defaultFeatureBranchConfig, config)
// get the feature branch config
Map buildFeatureConfig = (Map) config[BUILD_FEATURE] ?: [:]
config = MapUtils.merge(config, buildFeatureConfig)
Map scmConfig = (Map) config.get(SCM) ?: [:]
String scmUrl = scmConfig.get(SCM_URL) ?: null
// check wether to use configured scm or existing scm var
if (scmUrl == null) {
config[SCM] = config[SCM] ?: [:]
config[SCM][SCM_USE_SCM_VAR] = true
}
log.debug("config", config)
//calling buildDefault with scm configuration
buildDefault(config)
}
}