Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 1 | @Library('tcp-qa')_ |
| 2 | |
| 3 | def common = new com.mirantis.mk.Common() |
| 4 | def shared = new com.mirantis.system_qa.SharedPipeline() |
| 5 | def steps = "hardware,create_model,salt," + env.DRIVETRAIN_STACK_INSTALL + "," + env.PLATFORM_STACK_INSTALL |
| 6 | |
Dennis Dmitriev | 201a35e | 2018-08-06 01:37:05 +0300 | [diff] [blame] | 7 | currentBuild.description = "${NODE_NAME}:${ENV_NAME}" |
| 8 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 9 | def deploy(shared, common, steps) { |
| 10 | def report_text = '' |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 11 | try { |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 12 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 13 | stage("Clean the environment and clone tcp-qa") { |
| 14 | shared.prepare_working_dir() |
| 15 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 16 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 17 | stage("Create environment, generate model, bootstrap the salt-cluster") { |
| 18 | // steps: "hardware,create_model,salt" |
| 19 | shared.swarm_bootstrap_salt_cluster_devops() |
| 20 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 21 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 22 | stage("Install core infrastructure and deploy CICD nodes") { |
| 23 | // steps: env.DRIVETRAIN_STACK_INSTALL |
| 24 | shared.swarm_deploy_cicd(env.DRIVETRAIN_STACK_INSTALL) |
| 25 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 26 | |
Dennis Dmitriev | ee5ef23 | 2018-08-31 13:53:18 +0300 | [diff] [blame] | 27 | stage("Deploy platform components") { |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 28 | // steps: env.PLATFORM_STACK_INSTALL |
| 29 | shared.swarm_deploy_platform(env.PLATFORM_STACK_INSTALL) |
| 30 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 31 | |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 32 | currentBuild.result = 'SUCCESS' |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 33 | |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 34 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 35 | common.printMsg("Deploy is failed: " + e.message , "purple") |
| 36 | report_text = e.message |
| 37 | def snapshot_name = "deploy_failed" |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 38 | shared.run_cmd("""\ |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 39 | dos.py suspend ${ENV_NAME} || true |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 40 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 41 | """) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 42 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 43 | shared.run_cmd("""\ |
| 44 | dos.py resume ${ENV_NAME} || true |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 45 | """) |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 46 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 47 | shared.devops_snapshot_info(snapshot_name) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 48 | throw e |
| 49 | } finally { |
| 50 | shared.create_deploy_result_report(steps, currentBuild.result, report_text) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | def test(shared, common, steps) { |
| 55 | try { |
| 56 | stage("Run tests") { |
| 57 | shared.swarm_run_pytest(steps) |
| 58 | } |
| 59 | |
| 60 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 61 | common.printMsg("Tests are failed: " + e.message, "purple") |
| 62 | def snapshot_name = "tests_failed" |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 63 | shared.run_cmd("""\ |
| 64 | dos.py suspend ${ENV_NAME} || true |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 65 | dos.py snapshot ${ENV_NAME} ${snapshot_name} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 66 | """) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 67 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "false") { |
| 68 | shared.run_cmd("""\ |
| 69 | dos.py resume ${ENV_NAME} || true |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 70 | """) |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 71 | } |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 72 | shared.devops_snapshot_info(snapshot_name) |
| 73 | throw e |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | // main |
| 78 | throttle(['fuel_devops_environment']) { |
| 79 | node ("${NODE_NAME}") { |
| 80 | try { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 81 | // run deploy stages |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 82 | deploy(shared, common, steps) |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 83 | // run test stages |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 84 | test(shared, common, steps) |
| 85 | } catch (e) { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 86 | common.printMsg("Job is failed: " + e.message, "purple") |
Dennis Dmitriev | e4b831b | 2018-08-15 17:16:10 +0300 | [diff] [blame] | 87 | throw e |
| 88 | } finally { |
Dennis Dmitriev | b08c077 | 2018-10-17 15:10:26 +0300 | [diff] [blame] | 89 | // shutdown the environment if required |
| 90 | if ("${env.SHUTDOWN_ENV_ON_TEARDOWN}" == "true") { |
| 91 | shared.run_cmd("""\ |
| 92 | dos.py destroy ${ENV_NAME} || true |
| 93 | """) |
| 94 | } |
Dennis Dmitriev | fbf4227 | 2018-10-23 00:19:50 +0300 | [diff] [blame^] | 95 | |
| 96 | stage("Archive all xml reports") { |
| 97 | archiveArtifacts artifacts: "**/*.xml,**/*.ini,**/*.log,**/*.tar.gz" |
| 98 | } |
| 99 | stage("report results to testrail") { |
| 100 | shared.swarm_testrail_report(steps) |
| 101 | } |
| 102 | stage("Store TestRail reports to job description") { |
| 103 | def String description = readFile("description.txt") |
| 104 | currentBuild.description += "\n${description}" |
| 105 | } |
| 106 | |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 107 | } |
Dennis Dmitriev | fde667f | 2018-07-23 16:26:50 +0300 | [diff] [blame] | 108 | } |
Dennis Dmitriev | 6f8b0d0 | 2018-07-30 21:27:08 +0300 | [diff] [blame] | 109 | } |