blob: 86036cacbaddb3011f3808febb4f468e8da7da5b [file] [log] [blame]
Ales Komarek24097402017-05-22 16:28:10 +02001/**
2 *
Tomáš Kukrál0d00dd22017-07-27 14:28:36 +02003 * Launch stack and work with it
Ales Komarek24097402017-05-22 16:28:10 +02004 *
5 * Expected parameters:
6 * STACK_NAME Infrastructure stack name
Tomáš Kukrál4691f682017-07-27 16:36:12 +02007 * STACK_TEMPLATE File with stack template
8 * STACK_TYPE Deploy OpenStack/AWS [heat/aws], use 'physical' if no stack should be started
Ales Komarek24097402017-05-22 16:28:10 +02009 *
10 * STACK_TEMPLATE_URL URL to git repo with stack templates
11 * STACK_TEMPLATE_CREDENTIALS Credentials to the templates repo
12 * STACK_TEMPLATE_BRANCH Stack templates repo branch
13 *
14 * STACK_DELETE Delete stack when finished (bool)
Tomáš Kukrál4691f682017-07-27 16:36:12 +020015 * STACK_REUSE Reuse existing stack (don't create one, only read outputs)
Ales Komarek24097402017-05-22 16:28:10 +020016 * STACK_INSTALL What should be installed (k8s, openstack, ...)
17 * STACK_TEST Run tests (bool)
18 * STACK_CLEANUP_JOB Name of job for deleting stack
19 *
Tomáš Kukrál74f92862017-06-05 19:18:43 +020020 * STACK_COMPUTE_COUNT Number of compute nodes to launch
21 *
Ales Komarek24097402017-05-22 16:28:10 +020022 * AWS_STACK_REGION CloudFormation AWS region
23 * AWS_API_CREDENTIALS AWS Access key ID with AWS secret access key
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020024 * AWS_SSH_KEY AWS key pair name (used for SSH access)
Ales Komarek24097402017-05-22 16:28:10 +020025 *
26 * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
27 * HEAT_STACK_ZONE Heat stack availability zone
28 * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
29 * OPENSTACK_API_URL OpenStack API address
30 * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
31 * OPENSTACK_API_PROJECT OpenStack project to connect to
32 * OPENSTACK_API_CLIENT Versions of OpenStack python clients
33 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020034
Ales Komarek24097402017-05-22 16:28:10 +020035 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
Tomáš Kukrál4691f682017-07-27 16:36:12 +020036 * required for STACK_TYPE=physical
Ales Komarek24097402017-05-22 16:28:10 +020037 * SALT_MASTER_URL URL of Salt master
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020038
39 * Test settings:
40 * TEST_K8S_API_SERVER Kubernetes API address
41 * TEST_K8S_CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
Ales Komarek24097402017-05-22 16:28:10 +020042 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020043 * TEST_DOCKER_INSTALL Install docker on the target if true
44 * TEST_TEMPEST_IMAGE Tempest image link
45 * TEST_TEMPEST_PATTERN If not false, run tests matched to pattern only
46 * TEST_TEMPEST_TARGET Salt target for tempest node
Ales Komarek24097402017-05-22 16:28:10 +020047 *
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +020048 * optional parameters for overwriting soft params
49 * SALT_OVERRIDES YAML with overrides for Salt deployment
Ales Komarek24097402017-05-22 16:28:10 +020050 *
51 */
52common = new com.mirantis.mk.Common()
53git = new com.mirantis.mk.Git()
54openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020055aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020056orchestrate = new com.mirantis.mk.Orchestrate()
57salt = new com.mirantis.mk.Salt()
58test = new com.mirantis.mk.Test()
59
60_MAX_PERMITTED_STACKS = 2
61overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
62
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020063// Define global variables
Tomáš Kukrál31414a22017-06-09 14:17:53 +020064def saltMaster
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020065def venv
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020066
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020067if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020068 def aws_env_vars
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020069}
70
Ales Komarek24097402017-05-22 16:28:10 +020071timestamps {
72 node {
73 try {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020074 // Set build-specific variables
75 venv = "${env.WORKSPACE}/venv"
76
Ales Komarek24097402017-05-22 16:28:10 +020077 //
78 // Prepare machines
79 //
80 stage ('Create infrastructure') {
81
82 if (STACK_TYPE == 'heat') {
83 // value defaults
84 def openstackCloud
85 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
Ales Komarek24097402017-05-22 16:28:10 +020086
87 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
88 error("If you want to reuse existing stack you need to provide it's name")
89 }
90
91 if (STACK_REUSE.toBoolean() == false) {
92 // Don't allow to set custom heat stack name
93 wrap([$class: 'BuildUser']) {
94 if (env.BUILD_USER_ID) {
95 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
96 } else {
97 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
98 }
99 currentBuild.description = STACK_NAME
100 }
101 }
102
103 // set description
104 currentBuild.description = "${STACK_NAME}"
105
106 // get templates
107 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
108
109 // create openstack env
Tomáš Kukrál8fa9b672017-07-10 14:22:19 +0200110 openstack.setupOpenstackVirtualenv(venv, openstackVersion)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200111 openstackCloud = openstack.createOpenstackEnv(
112 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
113 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
114 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
115 OPENSTACK_API_VERSION)
Tomáš Kukrál8fa9b672017-07-10 14:22:19 +0200116 openstack.getKeystoneToken(openstackCloud, venv)
Ales Komarek24097402017-05-22 16:28:10 +0200117 //
118 // Verify possibility of create stack for given user and stack type
119 //
120 wrap([$class: 'BuildUser']) {
121 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
Tomáš Kukrál8fa9b672017-07-10 14:22:19 +0200122 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
Ales Komarek24097402017-05-22 16:28:10 +0200123 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
124 STACK_DELETE = "false"
125 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
126 }
127 }
128 }
129 // launch stack
130 if (STACK_REUSE.toBoolean() == false) {
131 stage('Launch new Heat stack') {
Ales Komarek24097402017-05-22 16:28:10 +0200132 envParams = [
Ales Komarek4f5e5f82017-07-25 15:48:53 +0200133 'cluster_zone': HEAT_STACK_ZONE,
134 'cluster_public_net': HEAT_STACK_PUBLIC_NET
Ales Komarek24097402017-05-22 16:28:10 +0200135 ]
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200136
137 // set reclass repo in heat env
138 try {
139 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
140 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
141 } catch (MissingPropertyException e) {
142 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
143 }
144
Tomáš Kukrál8fa9b672017-07-10 14:22:19 +0200145 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, false)
Ales Komarek24097402017-05-22 16:28:10 +0200146 }
147 }
148
149 // get SALT_MASTER_URL
Tomáš Kukrál8fa9b672017-07-10 14:22:19 +0200150 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200151 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ales Komarek24097402017-05-22 16:28:10 +0200152
153 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200154
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200155 } else if (STACK_TYPE == 'aws') {
Ales Komarek24097402017-05-22 16:28:10 +0200156
Tomáš Kukrál9af83062017-07-13 10:00:54 +0200157 // setup environment
158 aws.setupVirtualEnv(venv)
159
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200160 // set aws_env_vars
161 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200162
163 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
164 error("If you want to reuse existing stack you need to provide it's name")
165 }
166
167 if (STACK_REUSE.toBoolean() == false) {
168 // Don't allow to set custom stack name
169 wrap([$class: 'BuildUser']) {
170 if (env.BUILD_USER_ID) {
171 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
172 } else {
173 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
174 }
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200175 }
Tomáš Kukráldbf8ca82017-05-25 15:13:20 +0200176
177 // no underscore in STACK_NAME
178 STACK_NAME = STACK_NAME.replaceAll('_', '-')
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200179 }
180
181 // set description
Tomáš Kukráldbf8ca82017-05-25 15:13:20 +0200182 currentBuild.description = STACK_NAME
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200183
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200184 if (STACK_REUSE.toBoolean() == false) {
185 // get templates
186 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
187
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200188 // start stack
Tomáš Kukrálad79d322017-06-05 15:40:14 +0200189 def stack_params = [
190 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
191 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
192 ]
Tomáš Kukráldbb58402017-06-02 07:08:53 +0200193 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200194 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200195 }
196
197 // wait for stack to be ready
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200198 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200199
200 // get outputs
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200201 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200202 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
Ales Komarek24097402017-05-22 16:28:10 +0200203 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
Ales Komarek24097402017-05-22 16:28:10 +0200204
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200205 } else if (STACK_TYPE != 'physical') {
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200206 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
207 }
Ales Komarek24097402017-05-22 16:28:10 +0200208
Tomáš Kukrál20707642017-06-09 13:35:13 +0200209 // Connect to Salt master
Ales Komarek24097402017-05-22 16:28:10 +0200210 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
211 }
212
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200213
214 // Set up override params
215 if (env.getEnvironment().containsKey('SALT_OVERRIDES')) {
216 stage('Set Salt overrides') {
217 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
218 }
219 }
220
Ales Komarek24097402017-05-22 16:28:10 +0200221 //
222 // Install
223 //
224
225 if (common.checkContains('STACK_INSTALL', 'core')) {
226 stage('Install core infrastructure') {
227 orchestrate.installFoundationInfra(saltMaster)
228
229 if (common.checkContains('STACK_INSTALL', 'kvm')) {
230 orchestrate.installInfraKvm(saltMaster)
231 orchestrate.installFoundationInfra(saltMaster)
232 }
233
234 orchestrate.validateFoundationInfra(saltMaster)
235 }
236 }
237
238 // install k8s
239 if (common.checkContains('STACK_INSTALL', 'k8s')) {
vrovachev7be1e962017-07-05 13:28:26 +0400240
Ales Komarek24097402017-05-22 16:28:10 +0200241 stage('Install Kubernetes infra') {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200242 if (STACK_TYPE == 'aws') {
243 // configure kubernetes_control_address - save loadbalancer
244 def kubernetes_control_address = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer')
245 print(kubernetes_control_address)
246 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true)
247 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200248
Tomáš Kukrál4898be32017-06-19 09:54:15 +0200249 // ensure certificates are generated properly
250 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
251 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
252
Ales Komarek24097402017-05-22 16:28:10 +0200253 orchestrate.installKubernetesInfra(saltMaster)
254 }
255
vrovachev7be1e962017-07-05 13:28:26 +0400256 if (common.checkContains('STACK_INSTALL', 'contrail')) {
257 stage('Install Contrail for Kubernetes') {
258 orchestrate.installContrailNetwork(saltMaster)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200259 orchestrate.installContrailCompute(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400260 orchestrate.installKubernetesContrailCompute(saltMaster)
261 }
262 }
263
Ales Komarek24097402017-05-22 16:28:10 +0200264 stage('Install Kubernetes control') {
265
Ales Komarek24097402017-05-22 16:28:10 +0200266 orchestrate.installKubernetesControl(saltMaster)
267 }
268
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200269 stage('Scale Kubernetes computes') {
Tomáš Kukrálb9a7d6f2017-06-07 14:05:31 +0200270 if (STACK_COMPUTE_COUNT > 0) {
271 if (STACK_TYPE == 'aws') {
Tomáš Kukrálb9a7d6f2017-06-07 14:05:31 +0200272 // get stack info
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200273 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200274
Tomáš Kukrálb9a7d6f2017-06-07 14:05:31 +0200275 //update autoscaling group
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200276 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
Tomáš Kukrál8130a562017-06-06 11:09:22 +0200277
Tomáš Kukrálb9a7d6f2017-06-07 14:05:31 +0200278 // wait for computes to boot up
Tomáš Kukrála1d86b82017-07-10 17:24:01 +0200279 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
Tomáš Kukrálf31a5912017-06-13 15:47:25 +0200280 sleep(60)
Tomáš Kukrálb9a7d6f2017-06-07 14:05:31 +0200281 }
282
283 orchestrate.installKubernetesCompute(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200284 }
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200285 }
Ales Komarek24097402017-05-22 16:28:10 +0200286 }
287
288 // install openstack
289 if (common.checkContains('STACK_INSTALL', 'openstack')) {
290 // install Infra and control, tests, ...
291
292 stage('Install OpenStack infra') {
293 orchestrate.installOpenstackInfra(saltMaster)
294 }
295
296 stage('Install OpenStack control') {
297 orchestrate.installOpenstackControl(saltMaster)
298 }
299
300 stage('Install OpenStack network') {
301
302 if (common.checkContains('STACK_INSTALL', 'contrail')) {
303 orchestrate.installContrailNetwork(saltMaster)
304 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
305 orchestrate.installOpenstackNetwork(saltMaster)
306 }
307
308 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
309 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
310 }
311
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200312 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
313 stage('Install OpenStack Ironic conductor') {
314 orchestrate.installIronicConductor(saltMaster)
315 }
316 }
317
318
Ales Komarek24097402017-05-22 16:28:10 +0200319 stage('Install OpenStack compute') {
320 orchestrate.installOpenstackCompute(saltMaster)
321
322 if (common.checkContains('STACK_INSTALL', 'contrail')) {
323 orchestrate.installContrailCompute(saltMaster)
324 }
325 }
326
327 }
328
329
Martin Polreich46971102017-07-11 12:56:40 +0200330 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
331 stage('Install StackLight v1') {
332 orchestrate.installStacklightv1Control(saltMaster)
333 orchestrate.installStacklightv1Client(saltMaster)
334 }
335 }
336
Ales Komarek24097402017-05-22 16:28:10 +0200337 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
338 stage('Install StackLight') {
Martin Polreich46971102017-07-11 12:56:40 +0200339 orchestrate.installDockerSwarm(saltMaster)
340 orchestrate.installStacklight(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200341 }
342 }
343
344 //
345 // Test
346 //
347 def artifacts_dir = '_artifacts/'
348
349 if (common.checkContains('STACK_TEST', 'k8s')) {
350 stage('Run k8s bootstrap tests') {
351 def image = 'tomkukral/k8s-scripts'
352 def output_file = image.replaceAll('/', '-') + '.output'
353
354 // run image
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200355 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200356
357 // collect output
358 sh "mkdir -p ${artifacts_dir}"
359 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
360 writeFile file: "${artifacts_dir}${output_file}", text: file_content
361 sh "cat ${artifacts_dir}${output_file}"
362
363 // collect artifacts
364 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
365 }
366
367 stage('Run k8s conformance e2e tests') {
Ales Komarek24097402017-05-22 16:28:10 +0200368 def image = K8S_CONFORMANCE_IMAGE
369 def output_file = image.replaceAll('/', '-') + '.output'
370
371 // run image
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200372 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200373
374 // collect output
375 sh "mkdir -p ${artifacts_dir}"
376 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
377 writeFile file: "${artifacts_dir}${output_file}", text: file_content
378 sh "cat ${artifacts_dir}${output_file}"
379
380 // collect artifacts
381 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
382 }
383 }
384
385 if (common.checkContains('STACK_TEST', 'openstack')) {
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200386 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
387 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
388 }
389 stage('Run OpenStack tests') {
390 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200391 }
392
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200393 stage('Copy Tempest results to config node') {
394 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200395 }
396 }
397
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200398 if (common.checkContains('STACK_INSTALL', 'finalize')) {
399 stage('Finalize') {
400 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200401 }
402 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200403
Ales Komarek24097402017-05-22 16:28:10 +0200404 } catch (Throwable e) {
405 currentBuild.result = 'FAILURE'
406 throw e
407 } finally {
408
409
410 //
411 // Clean
412 //
413
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200414 if (STACK_NAME && STACK_NAME != '') {
Ales Komarek24097402017-05-22 16:28:10 +0200415 // send notification
416 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200417 }
Ales Komarek24097402017-05-22 16:28:10 +0200418
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200419 if (STACK_DELETE.toBoolean() == true) {
420 stage('Trigger cleanup job') {
421 common.errorMsg('Stack cleanup job triggered')
422 build(job: STACK_CLEANUP_JOB, parameters: [
423 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200424 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
425 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
426 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
427 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
428 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
429 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
430 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
431 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
432 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200433 ])
434 }
435 } else {
436 if (currentBuild.result == 'FAILURE') {
437 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Tomáš Kukrál5c2ec132017-07-26 09:57:27 +0200438
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200439 if (SALT_MASTER_URL) {
440 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200441 }
442 }
443 }
444 }
445 }
446}