blob: b34142706d5a5976ad04d213d44dfd370a5372b9 [file] [log] [blame]
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +02001/**
2 *
3 * Deploy the product cluster using Jenkins master on CICD cluster
4 *
5 * Expected parameters:
6 * STACKS List of deployments from 'all physical' view in the Jenkins
7 They should be separated by newline
8 * PARENT_NODE_NAME
9 * OS_AUTH_URL OpenStack keystone catalog URL
10 * OS_PROJECT_NAME OpenStack project (tenant) name
11 * OS_CREDENTIALS OpenStack username and password credentials ID in Jenkins
Hanna Arhipovaeb898752020-01-27 19:14:33 +020012 * OS_USER_DOMAIN_NAME OpenStack domain
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +020013
14 * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41
15 */
16@Library('tcp-qa')_
17
18common = new com.mirantis.mk.Common()
19shared = new com.mirantis.system_qa.SharedPipeline()
20import jenkins.model.*
21
22def stacks = env.STACKS.readLines()
23
24def get_last_build_time(job_name) {
25 def job = Hudson.instance.getJob(job_name)
26 def last_build = Jenkins.instance.getItemByFullName(job.fullName).getLastBuild()
27 if (last_build == null) {
28 return null
29 }
30 def upStreamBuild = Jenkins.getInstance().getItemByFullName(job.fullName).getBuildByNumber(last_build.getNumber())
31 return upStreamBuild.getTime()
32}
33
34@NonCPS
35def oldest_job(map) {
36 return map.sort({a, b -> a.value <=> b.value})*.key[0]
37}
38
39// ============================================================================
Hanna Arhipovafc3fe322020-06-04 16:30:10 +030040timeout(time: 23, unit: 'HOURS') {
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +020041 node (env.PARENT_NODE_NAME) {
42 stage("Remove extra stacks") {
43 withCredentials([
44 [$class : 'UsernamePasswordMultiBinding',
45 credentialsId : env.OS_CREDENTIALS,
46 passwordVariable: 'OS_PASSWORD',
47 usernameVariable: 'OS_USERNAME']
48 ]) {
49 env.OS_IDENTITY_API_VERSION = 3
50 for (stack_name in stacks) {
51 shared.run_cmd("""
Sergey Galkin320e0622020-01-27 17:52:26 +040052 export OS_IDENTITY_API_VERSION=3
53 export OS_AUTH_URL=${OS_AUTH_URL}
54 export OS_USERNAME=${OS_USERNAME}
55 export OS_PASSWORD=${OS_PASSWORD}
56 export OS_PROJECT_NAME=${OS_PROJECT_NAME}
Hanna Arhipovaeb898752020-01-27 19:14:33 +020057 export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME}
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +020058 openstack --insecure stack delete -y ${stack_name} || true
59 timeout 20m /bin/bash -c "while openstack --insecure stack show ${stack_name} -f value -c stack_status; do sleep 10; done";
60 """)
61 }
62 }
63 }
64
65 stage("Start deployment") {
66 def jobs_map = [:]
67 for (stack_name in stacks) {
68 jobs_map.put ("${stack_name}", get_last_build_time(stack_name))
69 }
70 stack_to_deploy = oldest_job(jobs_map)
71
72 println "Build ${stack_to_deploy}"
73 currentBuild.description = "${stack_to_deploy}"
74 // Trigger job
75 def deploy = build job: "${stack_to_deploy}",
Hanna Arhipova95659432020-01-28 14:24:02 +020076 parameters: [
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +020077 string(name: 'PARENT_NODE_NAME', value: env.PARENT_NODE_NAME),
78 string(name: 'OS_CREDENTIALS', value: env.OS_CREDENTIALS),
Hanna Arhipovaeb898752020-01-27 19:14:33 +020079 string(name: 'OS_AUTH_URL', value: env.OS_AUTH_URL),
80 string(name: 'OS_PROJECT_NAME', value: env.OS_PROJECT_NAME),
81 string(name: 'OS_USER_DOMAIN_NAME', value: env.OS_USER_DOMAIN_NAME),
Hanna Arhipovab0bfccd2020-01-15 11:19:00 +020082 string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS)
83 ]
84 }
85 }
86}