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) { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 12 | node ("${devNodeJenkinsName}") { |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 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: { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 21 | sh "maas login maas http://${maasHeadIP}/MAAS/api/2.0 ${apiKey}" |
| 22 | sh "maas maas machine release ${headNodeMAASSystemId}" |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 23 | |
| 24 | timeout(time: 15) { |
| 25 | waitUntil { |
| 26 | try { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 27 | sh "maas maas machine read ${headNodeMAASSystemId} | grep Ready" |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 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' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 36 | sh "maas maas machine deploy ${headNodeMAASSystemId}" |
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 { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 41 | sh "maas maas machine read ${headNodeMAASSystemId} | grep Deployed" |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 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 | |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 60 | stage 'Downloading CORD POD configuration' |
| 61 | sh 'vagrant ssh -c "cd /cord/build/config; git clone ${podConfigRepoUrl}" corddev' |
| 62 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 63 | stage 'Publish to headnode' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 64 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} publish" corddev' |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 65 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 66 | stage 'Deploy' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 67 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} deploy" corddev' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 68 | |
Luca Prete | a478ed8 | 2017-03-16 22:10:13 -0700 | [diff] [blame] | 69 | stage 'Power cycle compute nodes' |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 70 | parallel( |
| 71 | compute_1: { |
Luca Prete | 973c90a | 2017-03-17 16:44:33 -0700 | [diff] [blame] | 72 | sh 'ipmitool -U ${computeNode1IPMIUser} -P ${computeNode1IPMIPass} -H ${computeNode1IPMIIP} power cycle' |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 73 | }, compute_2: { |
Luca Prete | 973c90a | 2017-03-17 16:44:33 -0700 | [diff] [blame] | 74 | sh 'ipmitool -U ${computeNode2IPMIUser} -P ${computeNode2IPMIPass} -H ${computeNode2IPMIIP} power cycle' |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 75 | }, failFast : true |
| 76 | ) |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 77 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 78 | stage 'Wait for compute nodes to get deployed' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 79 | sh 'ssh-keygen -f "/home/ubuntu/.ssh/known_hosts" -R ${headNodeIP}' |
| 80 | def cordapikey = sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} sudo maas-region-admin apikey --username cord") |
| 81 | sh "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} maas login pod-maas http://${headNodeIP}/MAAS/api/1.0 $cordapikey" |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 82 | timeout(time: 45) { |
| 83 | waitUntil { |
| 84 | try { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 85 | num = sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -l ${headNodeUser} ${headNodeIP} maas pod-maas nodes list | grep Deployed | wc -l").trim() |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 86 | return num == '2' |
| 87 | } catch (exception) { |
| 88 | return false |
| 89 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 92 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 93 | stage 'Wait for computes nodes to be provisioned' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 94 | ip = sh (returnStdout: true, script:"sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim() |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 95 | timeout(time:45) { |
| 96 | waitUntil { |
| 97 | try { |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 98 | out = sh (returnStdout: true, script:"sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} curl -sS http://$ip:4243/provision/ | jq -c '.[] | select(.status | contains(2))'").trim() |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 99 | return out != "" |
| 100 | } catch (exception) { |
| 101 | return false |
| 102 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 105 | |
| 106 | stage 'Trigger Build' |
alshabib | 0e38854 | 2017-01-06 11:40:58 -0800 | [diff] [blame] | 107 | url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build' |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 108 | httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201' |
| 109 | |
| 110 | currentBuild.result = 'SUCCESS' |
| 111 | } catch (err) { |
| 112 | currentBuild.result = 'FAILURE' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 113 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false]) |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 114 | } finally { |
| 115 | sh 'vagrant destroy -f corddev' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 116 | sh 'rm -rf config/pod-configs' |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 117 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 118 | echo "RESULT: ${currentBuild.result}" |
| 119 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 120 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 121 | } |
alshabib | 152823c | 2016-09-07 23:49:12 -0700 | [diff] [blame] | 122 | } |