alshabib | 08d0a1f | 2017-01-05 15:04:28 -0800 | [diff] [blame] | 1 | def filename = 'manifest-${branch}.xml' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 2 | |
alshabib | 41f74fd | 2017-01-07 09:48:00 -0800 | [diff] [blame^] | 3 | node ('master') { |
| 4 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true] |
| 5 | |
| 6 | stage 'Generate and Copy Manifest file' |
| 7 | sh returnStdout: true, script: 'repo manifest -r -o ' + filename |
| 8 | sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp' |
| 9 | } |
| 10 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 11 | timeout (time: 240) { |
| 12 | node ('build') { |
| 13 | stage 'Checkout cord repo' |
alshabib | 513ca14 | 2017-01-05 15:06:24 -0800 | [diff] [blame] | 14 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true] |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 15 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 16 | dir('build') { |
| 17 | stage 'Redeploy head node and Build Vagrant box' |
| 18 | try { |
| 19 | parallel( |
| 20 | maasOps: { |
| 21 | sh "maas login maas http://10.90.0.2/MAAS/api/2.0 ${apiKey}" |
| 22 | sh "maas maas machine release ${systemId}" |
| 23 | |
| 24 | timeout(time: 15) { |
| 25 | waitUntil { |
| 26 | try { |
| 27 | sh "maas maas machine read ${systemId} | grep Ready" |
| 28 | return true |
| 29 | } catch (exception) { |
| 30 | return false |
| 31 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 32 | } |
| 33 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 34 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 35 | sh 'maas maas machines allocate' |
| 36 | sh "maas maas machine deploy ${systemId}" |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 37 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 38 | timeout(time: 30) { |
| 39 | waitUntil { |
| 40 | try { |
| 41 | sh "maas maas machine read ${systemId} | grep Deployed" |
| 42 | return true |
| 43 | } catch (exception) { |
| 44 | return false |
| 45 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 48 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 49 | }, vagrantOps: { |
| 50 | sh 'vagrant up corddev' |
| 51 | }, failFast : true |
| 52 | ) |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 53 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 54 | stage 'Fetch CORD packages' |
| 55 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 56 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 57 | stage 'Build CORD Images' |
| 58 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev' |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 59 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 60 | stage 'Publish to headnode' |
| 61 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=10.90.0.251:5000 -PdeployConfig=config/onlab_develop_pod.yml publish" corddev' |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 62 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 63 | stage 'Deploy' |
| 64 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=10.90.0.251:5000 -PdeployConfig=config/onlab_develop_pod.yml deploy" corddev' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 65 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 66 | stage 'Power cycle compute nodes' |
| 67 | parallel( |
| 68 | compute_1: { |
| 69 | sh 'ipmitool -U admin -P admin -H 10.90.0.10 power cycle' |
| 70 | }, compute_2: { |
| 71 | sh 'ipmitool -U admin -P admin -H 10.90.0.11 power cycle' |
| 72 | }, failFast : true |
| 73 | ) |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 74 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 75 | stage 'Wait for compute nodes to get deployed' |
| 76 | sh 'ssh-keygen -f "/home/ubuntu/.ssh/known_hosts" -R 10.90.0.251' |
| 77 | def cordapikey = sh(returnStdout: true, script: "sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 sudo maas-region-admin apikey --username cord") |
| 78 | sh "sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 maas login pod-maas http://10.90.0.251/MAAS/api/1.0 $cordapikey" |
| 79 | timeout(time: 45) { |
| 80 | waitUntil { |
| 81 | try { |
| 82 | num = sh(returnStdout: true, script: "sshpass -p ${headnodepass} ssh -l ${headnodeuser} 10.90.0.251 maas pod-maas nodes list | grep Deployed | wc -l").trim() |
| 83 | return num == '2' |
| 84 | } catch (exception) { |
| 85 | return false |
| 86 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 89 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 90 | stage 'Wait for computes nodes to be provisioned' |
| 91 | ip = sh (returnStdout: true, script:"sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim() |
| 92 | timeout(time:45) { |
| 93 | waitUntil { |
| 94 | try { |
| 95 | out = sh (returnStdout: true, script:"sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 curl -sS http://$ip:4243/provision/ | jq -c '.[] | select(.status | contains(2))'").trim() |
| 96 | return out != "" |
| 97 | } catch (exception) { |
| 98 | return false |
| 99 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 102 | |
| 103 | stage 'Trigger Build' |
alshabib | 0e38854 | 2017-01-06 11:40:58 -0800 | [diff] [blame] | 104 | url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build' |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 105 | httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201' |
| 106 | |
| 107 | currentBuild.result = 'SUCCESS' |
| 108 | } catch (err) { |
| 109 | currentBuild.result = 'FAILURE' |
| 110 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'cord-dev@opencord.org', sendToIndividuals: false]) |
| 111 | } finally { |
| 112 | sh 'vagrant destroy -f corddev' |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 113 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 114 | echo "RESULT: ${currentBuild.result}" |
| 115 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 116 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 117 | } |
alshabib | 152823c | 2016-09-07 23:49:12 -0700 | [diff] [blame] | 118 | } |