blob: 889c21da1693f894a2c82c2c283fd1830d2d2f6a [file] [log] [blame]
alshabib08d0a1f2017-01-05 15:04:28 -08001def filename = 'manifest-${branch}.xml'
alshabib4e1c96e2016-09-28 16:26:24 -07002
alshabib41f74fd2017-01-07 09:48:00 -08003node ('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
alshabib19302662017-01-05 14:27:41 -080011timeout (time: 240) {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070012 node ("${devNodeJenkinsName}") {
alshabib19302662017-01-05 14:27:41 -080013 stage 'Checkout cord repo'
alshabib513ca142017-01-05 15:06:24 -080014 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
alshabib19302662017-01-05 14:27:41 -080015
alshabib19302662017-01-05 14:27:41 -080016 dir('build') {
17 stage 'Redeploy head node and Build Vagrant box'
18 try {
19 parallel(
20 maasOps: {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070021 sh "maas login maas http://${maasHeadIP}/MAAS/api/2.0 ${apiKey}"
22 sh "maas maas machine release ${headNodeMAASSystemId}"
alshabib19302662017-01-05 14:27:41 -080023
24 timeout(time: 15) {
25 waitUntil {
26 try {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070027 sh "maas maas machine read ${headNodeMAASSystemId} | grep Ready"
alshabib19302662017-01-05 14:27:41 -080028 return true
29 } catch (exception) {
30 return false
31 }
alshabibef069942016-09-09 17:08:36 -070032 }
33 }
alshabib4e1c96e2016-09-28 16:26:24 -070034
alshabib19302662017-01-05 14:27:41 -080035 sh 'maas maas machines allocate'
Jonathan Hart1719e9a2017-03-13 21:53:47 -070036 sh "maas maas machine deploy ${headNodeMAASSystemId}"
alshabib4e1c96e2016-09-28 16:26:24 -070037
alshabib19302662017-01-05 14:27:41 -080038 timeout(time: 30) {
39 waitUntil {
40 try {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070041 sh "maas maas machine read ${headNodeMAASSystemId} | grep Deployed"
alshabib19302662017-01-05 14:27:41 -080042 return true
43 } catch (exception) {
44 return false
45 }
alshabibef069942016-09-09 17:08:36 -070046 }
47 }
alshabib4e1c96e2016-09-28 16:26:24 -070048
alshabib19302662017-01-05 14:27:41 -080049 }, vagrantOps: {
50 sh 'vagrant up corddev'
51 }, failFast : true
52 )
alshabib4e1c96e2016-09-28 16:26:24 -070053
alshabib19302662017-01-05 14:27:41 -080054 stage 'Fetch CORD packages'
55 sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev'
alshabib4e1c96e2016-09-28 16:26:24 -070056
alshabib19302662017-01-05 14:27:41 -080057 stage 'Build CORD Images'
58 sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev'
alshabib61509fb2016-09-09 02:43:20 -070059
Jonathan Hart1719e9a2017-03-13 21:53:47 -070060 stage 'Downloading CORD POD configuration'
61 sh 'vagrant ssh -c "cd /cord/build/config; git clone ${podConfigRepoUrl}" corddev'
62
alshabib19302662017-01-05 14:27:41 -080063 stage 'Publish to headnode'
Jonathan Hart1719e9a2017-03-13 21:53:47 -070064 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} publish" corddev'
alshabib61509fb2016-09-09 02:43:20 -070065
alshabib19302662017-01-05 14:27:41 -080066 stage 'Deploy'
Jonathan Hart1719e9a2017-03-13 21:53:47 -070067 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=${headNodeIP}:5000 -PdeployConfig=config/pod-configs/${podConfigFileName} deploy" corddev'
alshabib4e1c96e2016-09-28 16:26:24 -070068
Luca Pretea478ed82017-03-16 22:10:13 -070069 stage 'Power cycle compute nodes'
alshabib19302662017-01-05 14:27:41 -080070 parallel(
71 compute_1: {
Luca Prete973c90a2017-03-17 16:44:33 -070072 sh 'ipmitool -U ${computeNode1IPMIUser} -P ${computeNode1IPMIPass} -H ${computeNode1IPMIIP} power cycle'
alshabib19302662017-01-05 14:27:41 -080073 }, compute_2: {
Luca Prete973c90a2017-03-17 16:44:33 -070074 sh 'ipmitool -U ${computeNode2IPMIUser} -P ${computeNode2IPMIPass} -H ${computeNode2IPMIIP} power cycle'
alshabib19302662017-01-05 14:27:41 -080075 }, failFast : true
76 )
alshabib7f3be8d2016-09-27 18:04:56 -070077
alshabib19302662017-01-05 14:27:41 -080078 stage 'Wait for compute nodes to get deployed'
Luca Pretee0be67e2017-03-22 10:37:56 -070079 sh 'ssh-keygen -f /home/${devNodeUser}/.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 ${headNodeUser}")
Jonathan Hart1719e9a2017-03-13 21:53:47 -070081 sh "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} maas login pod-maas http://${headNodeIP}/MAAS/api/1.0 $cordapikey"
alshabib19302662017-01-05 14:27:41 -080082 timeout(time: 45) {
83 waitUntil {
84 try {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070085 num = sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -l ${headNodeUser} ${headNodeIP} maas pod-maas nodes list | grep Deployed | wc -l").trim()
alshabib19302662017-01-05 14:27:41 -080086 return num == '2'
87 } catch (exception) {
88 return false
89 }
alshabib4e1c96e2016-09-28 16:26:24 -070090 }
91 }
alshabib4e1c96e2016-09-28 16:26:24 -070092
alshabib19302662017-01-05 14:27:41 -080093 stage 'Wait for computes nodes to be provisioned'
Jonathan Hart1719e9a2017-03-13 21:53:47 -070094 ip = sh (returnStdout: true, script:"sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim()
alshabib19302662017-01-05 14:27:41 -080095 timeout(time:45) {
96 waitUntil {
97 try {
Jonathan Hart1719e9a2017-03-13 21:53:47 -070098 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()
alshabib19302662017-01-05 14:27:41 -080099 return out != ""
100 } catch (exception) {
101 return false
102 }
alshabib7f3be8d2016-09-27 18:04:56 -0700103 }
104 }
alshabib19302662017-01-05 14:27:41 -0800105
106 stage 'Trigger Build'
alshabib0e388542017-01-06 11:40:58 -0800107 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
alshabib19302662017-01-05 14:27:41 -0800108 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
109
110 currentBuild.result = 'SUCCESS'
111 } catch (err) {
112 currentBuild.result = 'FAILURE'
Jonathan Hart1719e9a2017-03-13 21:53:47 -0700113 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
alshabib19302662017-01-05 14:27:41 -0800114 } finally {
115 sh 'vagrant destroy -f corddev'
Jonathan Hart1719e9a2017-03-13 21:53:47 -0700116 sh 'rm -rf config/pod-configs'
alshabib7f3be8d2016-09-27 18:04:56 -0700117 }
alshabib19302662017-01-05 14:27:41 -0800118 echo "RESULT: ${currentBuild.result}"
119 }
alshabib7f3be8d2016-09-27 18:04:56 -0700120
alshabib19302662017-01-05 14:27:41 -0800121 }
alshabib152823c2016-09-07 23:49:12 -0700122}