blob: 6ce96c15e66106a3c836964a350df3355ec687c5 [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 */
Tomáš Kukrál3a17dd62017-07-27 18:24:16 +020052
Ales Komarek24097402017-05-22 16:28:10 +020053common = new com.mirantis.mk.Common()
54git = new com.mirantis.mk.Git()
55openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +020056aws = new com.mirantis.mk.Aws()
Ales Komarek24097402017-05-22 16:28:10 +020057orchestrate = new com.mirantis.mk.Orchestrate()
58salt = new com.mirantis.mk.Salt()
59test = new com.mirantis.mk.Test()
60
61_MAX_PERMITTED_STACKS = 2
62overwriteFile = "/srv/salt/reclass/classes/cluster/override.yml"
63
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020064// Define global variables
Tomáš Kukrál31414a22017-06-09 14:17:53 +020065def saltMaster
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020066def venv
Tomáš Kukrálbc4be252017-06-06 11:28:40 +020067
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020068if (STACK_TYPE == 'aws') {
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020069 def aws_env_vars
Tomáš Kukrálb19bdda2017-06-13 17:09:43 +020070}
71
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040072node("python") {
73 try {
74 // Set build-specific variables
75 venv = "${env.WORKSPACE}/venv"
Tomáš Kukrála1d86b82017-07-10 17:24:01 +020076
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040077 //
78 // Prepare machines
79 //
80 stage ('Create infrastructure') {
Ales Komarek24097402017-05-22 16:28:10 +020081
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040082 if (STACK_TYPE == 'heat') {
83 // value defaults
84 def openstackCloud
Ales Komarek24097402017-05-22 16:28:10 +020085
Ruslan Kamaldinov65144322017-08-02 15:16:55 +040086 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
87 error("If you want to reuse existing stack you need to provide it's name")
88 }
89
90 if (STACK_REUSE.toBoolean() == false) {
91 // Don't allow to set custom heat stack name
92 wrap([$class: 'BuildUser']) {
93 if (env.BUILD_USER_ID) {
94 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
95 } else {
96 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
97 }
98 currentBuild.description = STACK_NAME
Ales Komarek24097402017-05-22 16:28:10 +020099 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400100 }
Ales Komarek24097402017-05-22 16:28:10 +0200101
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400102 // set description
103 currentBuild.description = "${STACK_NAME}"
104
105 // get templates
106 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
107
108 // create openstack env
109 openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
110 openstackCloud = openstack.createOpenstackEnv(
111 OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
112 OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
113 OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN,
114 OPENSTACK_API_VERSION)
115 openstack.getKeystoneToken(openstackCloud, venv)
116 //
117 // Verify possibility of create stack for given user and stack type
118 //
119 wrap([$class: 'BuildUser']) {
120 if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins") && !STACK_REUSE.toBoolean()) {
121 def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", venv)
122 if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
123 STACK_DELETE = "false"
124 throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
125 }
126 }
127 }
128 // launch stack
129 if (STACK_REUSE.toBoolean() == false) {
130 stage('Launch new Heat stack') {
131 envParams = [
132 'cluster_zone': HEAT_STACK_ZONE,
133 'cluster_public_net': HEAT_STACK_PUBLIC_NET
134 ]
135
136 // set reclass repo in heat env
137 try {
138 envParams.put('cfg_reclass_branch', STACK_RECLASS_BRANCH)
139 envParams.put('cfg_reclass_address', STACK_RECLASS_ADDRESS)
140 } catch (MissingPropertyException e) {
141 common.infoMsg("Property STACK_RECLASS_BRANCH or STACK_RECLASS_ADDRESS not found! Using default values from template.")
142 }
143
144 openstack.createHeatStack(openstackCloud, STACK_NAME, STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, venv, false)
145 }
146 }
147
148 // get SALT_MASTER_URL
149 saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, STACK_NAME, 'salt_master_ip', venv)
150 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
151
152 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
153
154 } else if (STACK_TYPE == 'aws') {
155
156 // setup environment
157 aws.setupVirtualEnv(venv)
158
159 // set aws_env_vars
160 aws_env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
161
162 if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
163 error("If you want to reuse existing stack you need to provide it's name")
164 }
165
166 if (STACK_REUSE.toBoolean() == false) {
167 // Don't allow to set custom stack name
168 wrap([$class: 'BuildUser']) {
169 if (env.BUILD_USER_ID) {
170 STACK_NAME = "${env.BUILD_USER_ID}-${JOB_NAME}-${BUILD_NUMBER}"
171 } else {
172 STACK_NAME = "jenkins-${JOB_NAME}-${BUILD_NUMBER}"
Ales Komarek24097402017-05-22 16:28:10 +0200173 }
174 }
175
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400176 // no underscore in STACK_NAME
177 STACK_NAME = STACK_NAME.replaceAll('_', '-')
178 }
Ales Komarek24097402017-05-22 16:28:10 +0200179
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400180 // set description
181 currentBuild.description = STACK_NAME
182
183 if (STACK_REUSE.toBoolean() == false) {
Ales Komarek24097402017-05-22 16:28:10 +0200184 // get templates
185 git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
186
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400187 // start stack
188 def stack_params = [
189 "ParameterKey=KeyName,ParameterValue=" + AWS_SSH_KEY,
190 "ParameterKey=CmpNodeCount,ParameterValue=" + STACK_COMPUTE_COUNT
191 ]
192 def template_file = 'cfn/' + STACK_TEMPLATE + '.yml'
193 aws.createStack(venv, aws_env_vars, template_file, STACK_NAME, stack_params)
Tomáš Kukrál7a8a4fa2017-05-25 14:54:24 +0200194 }
Ales Komarek24097402017-05-22 16:28:10 +0200195
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400196 // wait for stack to be ready
197 aws.waitForStatus(venv, aws_env_vars, STACK_NAME, 'CREATE_COMPLETE')
198
199 // get outputs
200 saltMasterHost = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'SaltMasterIP')
201 currentBuild.description = "${STACK_NAME} ${saltMasterHost}"
202 SALT_MASTER_URL = "http://${saltMasterHost}:6969"
203
204 } else if (STACK_TYPE != 'physical') {
205 throw new Exception("STACK_TYPE ${STACK_TYPE} is not supported")
Ales Komarek24097402017-05-22 16:28:10 +0200206 }
207
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400208 // Connect to Salt master
209 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
210 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200211
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400212
213 // Set up override params
214 if (env.getEnvironment().containsKey('SALT_OVERRIDES')) {
215 stage('Set Salt overrides') {
216 salt.setSaltOverrides(saltMaster, SALT_OVERRIDES)
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200217 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400218 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200219
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400220 //
221 // Install
222 //
Ales Komarek24097402017-05-22 16:28:10 +0200223
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400224 if (common.checkContains('STACK_INSTALL', 'core')) {
225 stage('Install core infrastructure') {
226 orchestrate.installFoundationInfra(saltMaster)
227
228 if (common.checkContains('STACK_INSTALL', 'kvm')) {
229 orchestrate.installInfraKvm(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200230 orchestrate.installFoundationInfra(saltMaster)
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400231 }
Ales Komarek24097402017-05-22 16:28:10 +0200232
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400233 orchestrate.validateFoundationInfra(saltMaster)
234 }
235 }
Ales Komarek24097402017-05-22 16:28:10 +0200236
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400237 // install k8s
238 if (common.checkContains('STACK_INSTALL', 'k8s')) {
239
240 stage('Install Kubernetes infra') {
241 if (STACK_TYPE == 'aws') {
242 // configure kubernetes_control_address - save loadbalancer
243 def kubernetes_control_address = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ControlLoadBalancer')
244 print(kubernetes_control_address)
245 salt.runSaltProcessStep(saltMaster, 'I@salt:master', 'reclass.cluster_meta_set', ['kubernetes_control_address', kubernetes_control_address], null, true)
246 }
247
248 // ensure certificates are generated properly
249 salt.runSaltProcessStep(saltMaster, '*', 'saltutil.refresh_pillar', [], null, true)
250 salt.enforceState(saltMaster, '*', ['salt.minion.cert'], true)
251
252 orchestrate.installKubernetesInfra(saltMaster)
253 }
254
255 if (common.checkContains('STACK_INSTALL', 'contrail')) {
256 stage('Install Contrail for Kubernetes') {
257 orchestrate.installContrailNetwork(saltMaster)
258 orchestrate.installContrailCompute(saltMaster)
259 orchestrate.installKubernetesContrailCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200260 }
261 }
262
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400263 stage('Install Kubernetes control') {
vrovachev7be1e962017-07-05 13:28:26 +0400264
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400265 orchestrate.installKubernetesControl(saltMaster)
266 }
267
268 stage('Scale Kubernetes computes') {
269 if (STACK_COMPUTE_COUNT > 0) {
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200270 if (STACK_TYPE == 'aws') {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400271 // get stack info
272 def scaling_group = aws.getOutputs(venv, aws_env_vars, STACK_NAME, 'ComputesScalingGroup')
273
274 //update autoscaling group
275 aws.updateAutoscalingGroup(venv, aws_env_vars, scaling_group, ["--desired-capacity " + STACK_COMPUTE_COUNT])
276
277 // wait for computes to boot up
278 aws.waitForAutoscalingInstances(venv, aws_env_vars, scaling_group)
279 sleep(60)
Tomáš Kukrál39c96cd2017-07-11 10:14:13 +0200280 }
Tomáš Kukrál4691f682017-07-27 16:36:12 +0200281
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400282 orchestrate.installKubernetesCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200283 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400284 }
285 }
286
287 // install openstack
288 if (common.checkContains('STACK_INSTALL', 'openstack')) {
289 // install Infra and control, tests, ...
290
291 stage('Install OpenStack infra') {
292 orchestrate.installOpenstackInfra(saltMaster)
293 }
294
295 stage('Install OpenStack control') {
296 orchestrate.installOpenstackControl(saltMaster)
297 }
298
299 stage('Install OpenStack network') {
Ales Komarek24097402017-05-22 16:28:10 +0200300
vrovachev7be1e962017-07-05 13:28:26 +0400301 if (common.checkContains('STACK_INSTALL', 'contrail')) {
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400302 orchestrate.installContrailNetwork(saltMaster)
303 } else if (common.checkContains('STACK_INSTALL', 'ovs')) {
304 orchestrate.installOpenstackNetwork(saltMaster)
vrovachev7be1e962017-07-05 13:28:26 +0400305 }
306
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400307 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
308 salt.runSaltProcessStep(saltMaster, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
309 }
Ales Komarek24097402017-05-22 16:28:10 +0200310
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400311 if (salt.testTarget(saltMaster, 'I@ironic:conductor')){
312 stage('Install OpenStack Ironic conductor') {
313 orchestrate.installIronicConductor(saltMaster)
Tomáš Kukrál74f92862017-06-05 19:18:43 +0200314 }
Ales Komarek24097402017-05-22 16:28:10 +0200315 }
316
Ales Komarek24097402017-05-22 16:28:10 +0200317
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400318 stage('Install OpenStack compute') {
319 orchestrate.installOpenstackCompute(saltMaster)
Ales Komarek24097402017-05-22 16:28:10 +0200320
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400321 if (common.checkContains('STACK_INSTALL', 'contrail')) {
322 orchestrate.installContrailCompute(saltMaster)
Martin Polreich46971102017-07-11 12:56:40 +0200323 }
324 }
325
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400326 }
327
328
329 if (common.checkContains('STACK_INSTALL', 'sl-legacy')) {
330 stage('Install StackLight v1') {
331 orchestrate.installStacklightv1Control(saltMaster)
332 orchestrate.installStacklightv1Client(saltMaster)
333 }
334 }
335
336 if (common.checkContains('STACK_INSTALL', 'stacklight')) {
337 stage('Install StackLight') {
338 orchestrate.installDockerSwarm(saltMaster)
339 orchestrate.installStacklight(saltMaster)
340 }
341 }
342
343 //
344 // Test
345 //
346 def artifacts_dir = '_artifacts/'
347
348 if (common.checkContains('STACK_TEST', 'k8s')) {
349 stage('Run k8s bootstrap tests') {
350 def image = 'tomkukral/k8s-scripts'
351 def output_file = image.replaceAll('/', '-') + '.output'
352
353 // run image
354 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
355
356 // collect output
357 sh "mkdir -p ${artifacts_dir}"
358 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
359 writeFile file: "${artifacts_dir}${output_file}", text: file_content
360 sh "cat ${artifacts_dir}${output_file}"
361
362 // collect artifacts
363 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200364 }
365
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400366 stage('Run k8s conformance e2e tests') {
367 def image = K8S_CONFORMANCE_IMAGE
368 def output_file = image.replaceAll('/', '-') + '.output'
Ales Komarek24097402017-05-22 16:28:10 +0200369
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400370 // run image
371 test.runConformanceTests(saltMaster, TEST_K8S_API_SERVER, image)
Ales Komarek24097402017-05-22 16:28:10 +0200372
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400373 // collect output
374 sh "mkdir -p ${artifacts_dir}"
375 file_content = salt.getFileContent(saltMaster, 'ctl01*', '/tmp/' + output_file)
376 writeFile file: "${artifacts_dir}${output_file}", text: file_content
377 sh "cat ${artifacts_dir}${output_file}"
Ales Komarek24097402017-05-22 16:28:10 +0200378
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400379 // collect artifacts
380 archiveArtifacts artifacts: "${artifacts_dir}${output_file}"
381 }
382 }
Ales Komarek24097402017-05-22 16:28:10 +0200383
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400384 if (common.checkContains('STACK_TEST', 'openstack')) {
385 if (common.checkContains('TEST_DOCKER_INSTALL', 'true')) {
386 test.install_docker(saltMaster, TEST_TEMPEST_TARGET)
387 }
388 stage('Run OpenStack tests') {
389 test.runTempestTests(saltMaster, TEST_TEMPEST_IMAGE, TEST_TEMPEST_TARGET, TEST_TEMPEST_PATTERN)
Ales Komarek24097402017-05-22 16:28:10 +0200390 }
391
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400392 stage('Copy Tempest results to config node') {
393 test.copyTempestResults(saltMaster, TEST_TEMPEST_TARGET)
Ales Komarek24097402017-05-22 16:28:10 +0200394 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400395 }
Ales Komarek24097402017-05-22 16:28:10 +0200396
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400397 if (common.checkContains('STACK_INSTALL', 'finalize')) {
398 stage('Finalize') {
399 salt.runSaltProcessStep(saltMaster, '*', 'state.apply', [], null, true)
Ales Komarek24097402017-05-22 16:28:10 +0200400 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400401 }
Tomáš Kukrál53224c22017-07-26 10:53:20 +0200402
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400403 } catch (Throwable e) {
404 currentBuild.result = 'FAILURE'
405 throw e
406 } finally {
Ales Komarek24097402017-05-22 16:28:10 +0200407
408
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400409 //
410 // Clean
411 //
Ales Komarek24097402017-05-22 16:28:10 +0200412
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400413 if (STACK_NAME && STACK_NAME != '') {
414 // send notification
415 common.sendNotification(currentBuild.result, STACK_NAME, ["slack"])
416 }
417
418 if (STACK_DELETE.toBoolean() == true) {
419 stage('Trigger cleanup job') {
420 common.errorMsg('Stack cleanup job triggered')
421 build(job: STACK_CLEANUP_JOB, parameters: [
422 [$class: 'StringParameterValue', name: 'STACK_NAME', value: STACK_NAME],
423 [$class: 'StringParameterValue', name: 'STACK_TYPE', value: STACK_TYPE],
424 [$class: 'StringParameterValue', name: 'OPENSTACK_API_URL', value: OPENSTACK_API_URL],
425 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CREDENTIALS', value: OPENSTACK_API_CREDENTIALS],
426 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: OPENSTACK_API_PROJECT],
427 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_DOMAIN', value: OPENSTACK_API_PROJECT_DOMAIN],
428 [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT_ID', value: OPENSTACK_API_PROJECT_ID],
429 [$class: 'StringParameterValue', name: 'OPENSTACK_API_USER_DOMAIN', value: OPENSTACK_API_USER_DOMAIN],
430 [$class: 'StringParameterValue', name: 'OPENSTACK_API_CLIENT', value: OPENSTACK_API_CLIENT],
431 [$class: 'StringParameterValue', name: 'OPENSTACK_API_VERSION', value: OPENSTACK_API_VERSION]
432 ])
Tomáš Kukrál439c62e2017-06-02 11:42:36 +0200433 }
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400434 } else {
435 if (currentBuild.result == 'FAILURE') {
436 common.errorMsg("Deploy job FAILED and was not deleted. Please fix the problem and delete stack on you own.")
Ales Komarek24097402017-05-22 16:28:10 +0200437
Ruslan Kamaldinov65144322017-08-02 15:16:55 +0400438 if (SALT_MASTER_URL) {
439 common.errorMsg("Salt master URL: ${SALT_MASTER_URL}")
Ales Komarek24097402017-05-22 16:28:10 +0200440 }
441 }
442 }
443 }
444}