blob: 28232e77fa2e340af1a9f388fb10015f47321b80 [file] [log] [blame]
alshabib08d0a1f2017-01-05 15:04:28 -08001def filename = 'manifest-${branch}.xml'
Luca Prete283f80a2017-05-18 15:21:24 -07002def manifestUrl = 'https://gerrit.opencord.org/manifest'
alshabib4e1c96e2016-09-28 16:26:24 -07003
alshabib41f74fd2017-01-07 09:48:00 -08004node ('master') {
Luca Prete283f80a2017-05-18 15:21:24 -07005 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
alshabib41f74fd2017-01-07 09:48:00 -08006
Luca Prete283f80a2017-05-18 15:21:24 -07007 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 }
alshabib41f74fd2017-01-07 09:48:00 -080011}
12
Luca Prete283f80a2017-05-18 15:21:24 -070013node ("${devNodeJenkinsName}") {
14 timeout (time: 240) {
alshabib19302662017-01-05 14:27:41 -080015 stage 'Checkout cord repo'
Luca Prete283f80a2017-05-18 15:21:24 -070016 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
alshabib19302662017-01-05 14:27:41 -080017
alshabib19302662017-01-05 14:27:41 -080018 dir('build') {
alshabib19302662017-01-05 14:27:41 -080019 try {
Luca Prete283f80a2017-05-18 15:21:24 -070020 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}"
alshabib19302662017-01-05 14:27:41 -080025
Luca Prete283f80a2017-05-18 15:21:24 -070026 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 }
alshabib19302662017-01-05 14:27:41 -080034 }
alshabibef069942016-09-09 17:08:36 -070035 }
alshabib4e1c96e2016-09-28 16:26:24 -070036
Luca Prete283f80a2017-05-18 15:21:24 -070037 sh 'maas maas machines allocate'
38 sh "maas maas machine deploy ${headNodeMAASSystemId}"
alshabib4e1c96e2016-09-28 16:26:24 -070039
Luca Prete283f80a2017-05-18 15:21:24 -070040 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 }
alshabib19302662017-01-05 14:27:41 -080048 }
alshabibef069942016-09-09 17:08:36 -070049 }
alshabib4e1c96e2016-09-28 16:26:24 -070050
Luca Prete283f80a2017-05-18 15:21:24 -070051 }, vagrantOps: {
52 sh 'vagrant up corddev'
53 }, failFast : true
54 )
55 }
alshabib4e1c96e2016-09-28 16:26:24 -070056
Luca Prete283f80a2017-05-18 15:21:24 -070057 stage ("Fetch CORD packages") {
58 sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev'
59 }
alshabib4e1c96e2016-09-28 16:26:24 -070060
Luca Prete283f80a2017-05-18 15:21:24 -070061 stage ("Build CORD Images") {
62 sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev'
63 }
alshabib61509fb2016-09-09 02:43:20 -070064
Luca Prete283f80a2017-05-18 15:21:24 -070065 stage ("Downloading CORD POD configuration") {
66 sh 'vagrant ssh -c "cd /cord/build/config; git clone ${podConfigRepoUrl}" corddev'
67 }
Jonathan Hart1719e9a2017-03-13 21:53:47 -070068
Luca Prete283f80a2017-05-18 15:21:24 -070069 stage ("Publish to headnode") {
70 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} publish" corddev'
71 }
alshabib61509fb2016-09-09 02:43:20 -070072
Luca Prete283f80a2017-05-18 15:21:24 -070073 stage ("Deploy") {
74 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} deploy" corddev'
75 }
alshabib4e1c96e2016-09-28 16:26:24 -070076
Luca Prete283f80a2017-05-18 15:21:24 -070077 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 }
alshabib7f3be8d2016-09-27 18:04:56 -070086
Luca Prete283f80a2017-05-18 15:21:24 -070087 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 }
alshabib19302662017-01-05 14:27:41 -080099 }
alshabib4e1c96e2016-09-28 16:26:24 -0700100 }
101 }
alshabib4e1c96e2016-09-28 16:26:24 -0700102
Luca Prete283f80a2017-05-18 15:21:24 -0700103 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 }
alshabib19302662017-01-05 14:27:41 -0800113 }
alshabib7f3be8d2016-09-27 18:04:56 -0700114 }
115 }
alshabib19302662017-01-05 14:27:41 -0800116
Luca Prete283f80a2017-05-18 15:21:24 -0700117 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 }
alshabib19302662017-01-05 14:27:41 -0800121
122 currentBuild.result = 'SUCCESS'
123 } catch (err) {
124 currentBuild.result = 'FAILURE'
Jonathan Hart1719e9a2017-03-13 21:53:47 -0700125 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
alshabib19302662017-01-05 14:27:41 -0800126 } finally {
127 sh 'vagrant destroy -f corddev'
Jonathan Hart1719e9a2017-03-13 21:53:47 -0700128 sh 'rm -rf config/pod-configs'
alshabib7f3be8d2016-09-27 18:04:56 -0700129 }
alshabib19302662017-01-05 14:27:41 -0800130 echo "RESULT: ${currentBuild.result}"
131 }
alshabib7f3be8d2016-09-27 18:04:56 -0700132
alshabib19302662017-01-05 14:27:41 -0800133 }
alshabib152823c2016-09-07 23:49:12 -0700134}
Luca Prete283f80a2017-05-18 15:21:24 -0700135
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 */
143def 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 */
154def createMACIPbindingStr(mac, ip) {
155 return """host ${mac} {
156hardware ethernet ${mac};
157fixed-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 */
166def runHeadCmd(command) {
167 return sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} ${command}")
168}