alshabib | 08d0a1f | 2017-01-05 15:04:28 -0800 | [diff] [blame] | 1 | def filename = 'manifest-${branch}.xml' |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 2 | def manifestUrl = 'https://gerrit.opencord.org/manifest' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 3 | |
alshabib | 41f74fd | 2017-01-07 09:48:00 -0800 | [diff] [blame] | 4 | node ('master') { |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 5 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true] |
alshabib | 41f74fd | 2017-01-07 09:48:00 -0800 | [diff] [blame] | 6 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 7 | stage ("Generate and Copy Manifest file") { |
| 8 | sh returnStdout: true, script: 'repo manifest -r -o ' + filename |
| 9 | sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp' |
| 10 | } |
alshabib | 41f74fd | 2017-01-07 09:48:00 -0800 | [diff] [blame] | 11 | } |
| 12 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 13 | node ("${devNodeJenkinsName}") { |
| 14 | timeout (time: 240) { |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 15 | stage 'Checkout cord repo' |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 16 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true] |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 17 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 18 | dir('build') { |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 19 | try { |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 20 | stage ("Re-deploy head node and Build Vagrant box") { |
| 21 | parallel( |
| 22 | maasOps: { |
| 23 | sh "maas login maas http://${maasHeadIP}/MAAS/api/2.0 ${apiKey}" |
| 24 | sh "maas maas machine release ${headNodeMAASSystemId}" |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 25 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 26 | timeout(time: 15) { |
| 27 | waitUntil { |
| 28 | try { |
| 29 | sh "maas maas machine read ${headNodeMAASSystemId} | grep Ready" |
| 30 | return true |
| 31 | } catch (exception) { |
| 32 | return false |
| 33 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 34 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 35 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 36 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 37 | sh 'maas maas machines allocate' |
| 38 | sh "maas maas machine deploy ${headNodeMAASSystemId}" |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 39 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 40 | timeout(time: 30) { |
| 41 | waitUntil { |
| 42 | try { |
| 43 | sh "maas maas machine read ${headNodeMAASSystemId} | grep Deployed" |
| 44 | return true |
| 45 | } catch (exception) { |
| 46 | return false |
| 47 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 48 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 49 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 50 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 51 | }, vagrantOps: { |
| 52 | sh 'vagrant up corddev' |
| 53 | }, failFast : true |
| 54 | ) |
| 55 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 56 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 57 | stage ("Fetch CORD packages") { |
| 58 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev' |
| 59 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 60 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 61 | stage ("Build CORD Images") { |
| 62 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev' |
| 63 | } |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 64 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 65 | stage ("Downloading CORD POD configuration") { |
| 66 | sh 'vagrant ssh -c "cd /cord/build/config; git clone ${podConfigRepoUrl}" corddev' |
| 67 | } |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 68 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 69 | stage ("Publish to headnode") { |
| 70 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} publish" corddev' |
| 71 | } |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 72 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 73 | stage ("Deploy") { |
| 74 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} deploy" corddev' |
| 75 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 76 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 77 | stage ("Power cycle compute nodes") { |
| 78 | parallel( |
| 79 | compute_1: { |
| 80 | sh 'ipmitool -U ${computeNode1IPMIUser} -P ${computeNode1IPMIPass} -H ${computeNode1IPMIIP} power cycle' |
| 81 | }, compute_2: { |
| 82 | sh 'ipmitool -U ${computeNode2IPMIUser} -P ${computeNode2IPMIPass} -H ${computeNode2IPMIIP} power cycle' |
| 83 | }, failFast : true |
| 84 | ) |
| 85 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 86 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 87 | stage ("Wait for compute nodes to get deployed") { |
| 88 | sh 'ssh-keygen -f /home/${devNodeUser}/.ssh/known_hosts -R ${headNodeIP}' |
| 89 | def cordapikey = runHeadCmd("sudo maas-region-admin apikey --username ${headNodeUser}") |
| 90 | runHeadCmd("maas login pod-maas http://${headNodeIP}/MAAS/api/1.0 $cordapikey") |
| 91 | timeout(time: 45) { |
| 92 | waitUntil { |
| 93 | try { |
| 94 | num = runHeadCmd("maas pod-maas nodes list | grep Deployed | wc -l").trim() |
| 95 | return num == '2' |
| 96 | } catch (exception) { |
| 97 | return false |
| 98 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 99 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 102 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 103 | stage ("Wait for computes nodes to be provisioned") { |
| 104 | ip = runHeadCmd("docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim() |
| 105 | timeout(time:45) { |
| 106 | waitUntil { |
| 107 | try { |
| 108 | out = runHeadCmd("curl -sS http://$ip:4243/provision/ | jq -c '.[] | select(.status | contains(2))'").trim() |
| 109 | return out != "" |
| 110 | } catch (exception) { |
| 111 | return false |
| 112 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 113 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 116 | |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 117 | stage ("Trigger Build") { |
| 118 | url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build' |
| 119 | httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201' |
| 120 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 121 | |
| 122 | currentBuild.result = 'SUCCESS' |
| 123 | } catch (err) { |
| 124 | currentBuild.result = 'FAILURE' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 125 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false]) |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 126 | } finally { |
| 127 | sh 'vagrant destroy -f corddev' |
Jonathan Hart | 1719e9a | 2017-03-13 21:53:47 -0700 | [diff] [blame] | 128 | sh 'rm -rf config/pod-configs' |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 129 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 130 | echo "RESULT: ${currentBuild.result}" |
| 131 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 132 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 133 | } |
alshabib | 152823c | 2016-09-07 23:49:12 -0700 | [diff] [blame] | 134 | } |
Luca Prete | 283f80a | 2017-05-18 15:21:24 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Transforms a multiline string into an array. |
| 138 | * Each line is a value of the array. |
| 139 | * |
| 140 | * @param the multiline string to transform |
| 141 | * @return the computed array |
| 142 | */ |
| 143 | def multiStringToArray(str) { |
| 144 | return str.split("\\r?\\n") as String[] |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Returns a string used to bind IPs and MAC addresses, substituting the values |
| 149 | * given. |
| 150 | * |
| 151 | * @param mac the MAC address to substitute |
| 152 | * @param ip the IP address to substitute |
| 153 | */ |
| 154 | def createMACIPbindingStr(mac, ip) { |
| 155 | return """host ${mac} { |
| 156 | hardware ethernet ${mac}; |
| 157 | fixed-address ${ip}; |
| 158 | }""" |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Runs a command on the head node. |
| 163 | * |
| 164 | * @param command the command to run on the head node |
| 165 | */ |
| 166 | def runHeadCmd(command) { |
| 167 | return sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} ${command}") |
| 168 | } |