-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.create
113 lines (99 loc) · 3.9 KB
/
Jenkinsfile.create
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
111
112
113
/*
* Copyright (c) 2019 Risk Focus Inc.
*
* 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.
*/
def jobParametersList = [
'GENERIC' : [],
'K8 Namespace': []
]
def envTypeFolder = ''
def APPLICATION_REPO = "https://github.com/riskfocus/${PROJECT_PREFIX}-infra"
withFolderProperties {
if (env.CADMIUM_YAML_REPO)
APPLICATION_REPO = CADMIUM_YAML_REPO
}
def jobParameters = [
string(name: "NAMESPACE", defaultValue: "", description: "Environment name/Namespace"),
choice(name: 'ENVIRONMENT_TYPE', choices: GLOBAL_ENABLED_ENVIRONMENT_TYPE, description: 'Platform type'),
choice(name: 'SCHEDULE_NAME', choices: ['default', '_CUSTOM_', 'stop-in-2h', 'stop-in-4h', 'stop-in-8h'].join('\n'), description: 'Start/Stop/lifetime schedule to use (defined in DynamoDB). "default" is safe, to provide custom name - select _CUSTOM_ and use SCHEDULE_NAME_CUSTOM'),
string(name: 'SCHEDULE_NAME_CUSTOM', defaultValue: '', description: 'Provide custom schedule name'),
string(name: "APPLICATION_REPO", defaultValue: APPLICATION_REPO, description: "Application git repo with cadmium.yaml")
]
jobParameters += jobParametersList.findAll { it.key in GLOBAL_ENABLED_ENVIRONMENT_TYPE }.collect { it.value }.flatten()
properties([parameters(jobParameters)])
if (!(params.NAMESPACE))
error("Parameter NAMESPACE was not supplied, aborting")
// Script scoped vars
scmVars = null
cadmium = null
flavor_params = [:]
// Default Value
// Value will be overrided with SCHEDULE_NAME_CUSTOM(if it is provided) or
// with value from cadmium.yaml if params.SCHEDULE_NAME == 'default'
schedule = params.SCHEDULE_NAME
ansiColor('xterm') {
timestamps {
node() {
currentBuild.description = "[${params.NAMESPACE}] "
stage("Reading cadmium.yaml") {
git url: params.APPLICATION_REPO, credentialsId: "cadmium", branch: "master"
cadmium = readYaml file: 'cadmium.yaml'
scmVars = checkout scm
}
// TODO feels like OOP
switch (params.ENVIRONMENT_TYPE) {
case 'K8 Namespace':
if (cadmium.version == 0.1) {
envTypeFolder = 'k8s-jx'
} else {
envTypeFolder = 'k8s-namespace'
}
break
case 'GENERIC':
envTypeFolder = 'generic'
break
}
stage("Creating environment folder") {
if (params.SCHEDULE_NAME_CUSTOM) {
schedule = params.SCHEDULE_NAME_CUSTOM
} else if (cadmium.schedule && schedule == 'default') {
schedule = cadmium.schedule
}
def startJobText = ""
def stopJobText = ""
if (!cadmium.settings?.disableRhodiumIntegration) {
dir("infrastructure_types/${envTypeFolder}") {
startJobText = readFile 'start_env.groovy'
stopJobText = readFile 'stop_env.groovy'
}
}
jobDsl targets: "dsl/envFolder.groovy", additionalParameters: [
NAMESPACE : params.NAMESPACE,
ENVIRONMENT_TYPE : params.ENVIRONMENT_TYPE,
SCHEDULE_NAME : schedule,
APPLICATION_REPO : params.APPLICATION_REPO,
REPO_URL : scmVars.GIT_URL,
CADMIUM : cadmium,
ORIG_PARAMS_MAP : params,
FLAVOR_PARAMS_MAPS: flavor_params,
START_JOB_TEXT : startJobText,
STOP_JOB_TEXT : stopJobText,
]
}
dir("infrastructure_types/${envTypeFolder}") {
load 'create.groovy'
}
}
}
}