Hanna Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 1 | /** |
| 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 Arhipova | eb89875 | 2020-01-27 19:14:33 +0200 | [diff] [blame] | 12 | * OS_USER_DOMAIN_NAME OpenStack domain |
Hanna Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 13 | |
| 14 | * TCP_QA_REFS Reference to the tcp-qa change on Gerrit, like refs/changes/46/418546/41 |
| 15 | */ |
| 16 | @Library('tcp-qa')_ |
| 17 | |
| 18 | common = new com.mirantis.mk.Common() |
| 19 | shared = new com.mirantis.system_qa.SharedPipeline() |
| 20 | import jenkins.model.* |
| 21 | |
| 22 | def stacks = env.STACKS.readLines() |
| 23 | |
| 24 | def 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 |
| 35 | def oldest_job(map) { |
| 36 | return map.sort({a, b -> a.value <=> b.value})*.key[0] |
| 37 | } |
| 38 | |
| 39 | // ============================================================================ |
Hanna Arhipova | fc3fe32 | 2020-06-04 16:30:10 +0300 | [diff] [blame] | 40 | timeout(time: 23, unit: 'HOURS') { |
Hanna Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 41 | 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 Galkin | 320e062 | 2020-01-27 17:52:26 +0400 | [diff] [blame] | 52 | 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 Arhipova | eb89875 | 2020-01-27 19:14:33 +0200 | [diff] [blame] | 57 | export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME} |
Hanna Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 58 | 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 Arhipova | 9565943 | 2020-01-28 14:24:02 +0200 | [diff] [blame] | 76 | parameters: [ |
Hanna Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 77 | string(name: 'PARENT_NODE_NAME', value: env.PARENT_NODE_NAME), |
| 78 | string(name: 'OS_CREDENTIALS', value: env.OS_CREDENTIALS), |
Hanna Arhipova | eb89875 | 2020-01-27 19:14:33 +0200 | [diff] [blame] | 79 | 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 Arhipova | b0bfccd | 2020-01-15 11:19:00 +0200 | [diff] [blame] | 82 | string(name: 'TCP_QA_REFS', value: env.TCP_QA_REFS) |
| 83 | ] |
| 84 | } |
| 85 | } |
| 86 | } |