blob: 3aeae45b317618cd77df0a3c8d385a78f7fd7866 [file] [log] [blame]
alshabib82e7fbc2017-01-06 11:41:41 -08001def filename = 'manifest-${branch}.xml'
alshabib4e1c96e2016-09-28 16:26:24 -07002
alshabib23ac16d2017-01-07 09:46:43 -08003node ('master') {
alshabib82e7fbc2017-01-06 11:41:41 -08004 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'
alshabib23ac16d2017-01-07 09:46:43 -08009}
10
11timeout (time: 240) {
Luca Prete4bcfe472017-03-08 09:44:09 -080012 node ("${devNodeJenkinsName}") {
alshabib23ac16d2017-01-07 09:46:43 -080013 stage 'Checkout cord repo'
14 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
alshabib82e7fbc2017-01-06 11:41:41 -080015
16 dir('build') {
17 stage 'Redeploy head node and Build Vagrant box'
18 try {
19 parallel(
20 maasOps: {
Luca Pretebd0bedd2017-03-07 13:53:51 -080021 sh "maas login maas http://${maasHeadIP}/MAAS/api/2.0 ${apiKey}"
22 sh "maas maas machine release ${headNodeMAASSystemId}"
alshabib82e7fbc2017-01-06 11:41:41 -080023
24 timeout(time: 15) {
25 waitUntil {
26 try {
Luca Pretebd0bedd2017-03-07 13:53:51 -080027 sh "maas maas machine read ${headNodeMAASSystemId} | grep Ready"
alshabib82e7fbc2017-01-06 11:41: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
alshabib82e7fbc2017-01-06 11:41:41 -080035 sh 'maas maas machines allocate'
Luca Pretebd0bedd2017-03-07 13:53:51 -080036 sh "maas maas machine deploy ${headNodeMAASSystemId}"
alshabib4e1c96e2016-09-28 16:26:24 -070037
alshabib82e7fbc2017-01-06 11:41:41 -080038 timeout(time: 30) {
39 waitUntil {
40 try {
Luca Pretebd0bedd2017-03-07 13:53:51 -080041 sh "maas maas machine read ${headNodeMAASSystemId} | grep Deployed"
alshabib82e7fbc2017-01-06 11:41: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
alshabib82e7fbc2017-01-06 11:41:41 -080049 }, vagrantOps: {
50 sh 'vagrant up corddev'
51 }, failFast : true
52 )
alshabib4e1c96e2016-09-28 16:26:24 -070053
alshabib82e7fbc2017-01-06 11:41:41 -080054 stage 'Fetch CORD packages'
55 sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev'
alshabib4e1c96e2016-09-28 16:26:24 -070056
alshabib82e7fbc2017-01-06 11:41:41 -080057 stage 'Build CORD Images'
58 sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev'
alshabib61509fb2016-09-09 02:43:20 -070059
Luca Pretee2b36202017-03-10 14:19:38 -080060 stage 'Downloading CORD POD configuration'
Luca Pretedbaedee2017-03-14 11:08:45 -070061 sh 'vagrant ssh -c "cd /cord/build/config; git clone ${podConfigRepoUrl} -b ${branch}" corddev'
Luca Prete2bec54d2017-03-10 10:40:17 -080062
alshabib82e7fbc2017-01-06 11:41:41 -080063 stage 'Publish to headnode'
Luca Pretee2b36202017-03-10 14:19:38 -080064 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
alshabib82e7fbc2017-01-06 11:41:41 -080066 stage 'Deploy'
Luca Pretee2b36202017-03-10 14:19:38 -080067 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
alshabib82e7fbc2017-01-06 11:41:41 -080069 stage 'Power cycle compute nodes'
70 parallel(
71 compute_1: {
Luca Prete70f69162017-03-17 16:42:25 -070072 sh 'ipmitool -U ${computeNode1IPMIUser} -P ${computeNode1IPMIPass} -H ${computeNode1IPMIIP} power cycle'
alshabib82e7fbc2017-01-06 11:41:41 -080073 }, compute_2: {
Luca Prete70f69162017-03-17 16:42:25 -070074 sh 'ipmitool -U ${computeNode2IPMIUser} -P ${computeNode2IPMIPass} -H ${computeNode2IPMIIP} power cycle'
alshabib82e7fbc2017-01-06 11:41:41 -080075 }, failFast : true
76 )
alshabib7f3be8d2016-09-27 18:04:56 -070077
alshabib82e7fbc2017-01-06 11:41:41 -080078 stage 'Wait for compute nodes to get deployed'
Luca Prete0526e732017-03-22 10:34:15 -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}")
Luca Pretebd0bedd2017-03-07 13:53:51 -080081 sh "sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} maas login pod-maas http://${headNodeIP}/MAAS/api/1.0 $cordapikey"
alshabib82e7fbc2017-01-06 11:41:41 -080082 timeout(time: 45) {
83 waitUntil {
84 try {
Luca Pretebd0bedd2017-03-07 13:53:51 -080085 num = sh(returnStdout: true, script: "sshpass -p ${headNodePass} ssh -l ${headNodeUser} ${headNodeIP} maas pod-maas nodes list | grep Deployed | wc -l").trim()
alshabib82e7fbc2017-01-06 11:41: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
alshabib82e7fbc2017-01-06 11:41:41 -080093 stage 'Wait for computes nodes to be provisioned'
Luca Pretebd0bedd2017-03-07 13:53:51 -080094 ip = sh (returnStdout: true, script:"sshpass -p ${headNodePass} ssh -oStrictHostKeyChecking=no -l ${headNodeUser} ${headNodeIP} docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim()
alshabib82e7fbc2017-01-06 11:41:41 -080095 timeout(time:45) {
96 waitUntil {
97 try {
Luca Pretebd0bedd2017-03-07 13:53:51 -080098 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()
alshabib82e7fbc2017-01-06 11:41:41 -080099 return out != ""
100 } catch (exception) {
101 return false
102 }
alshabib7f3be8d2016-09-27 18:04:56 -0700103 }
104 }
alshabib82e7fbc2017-01-06 11:41:41 -0800105
106 stage 'Trigger Build'
107 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
108 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
109
110 currentBuild.result = 'SUCCESS'
111 } catch (err) {
112 currentBuild.result = 'FAILURE'
Luca Prete2bec54d2017-03-10 10:40:17 -0800113 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
alshabib82e7fbc2017-01-06 11:41:41 -0800114 } finally {
115 sh 'vagrant destroy -f corddev'
Luca Prete6f9f8482017-03-10 16:46:20 -0800116 sh 'rm -rf config/pod-configs'
alshabib7f3be8d2016-09-27 18:04:56 -0700117 }
alshabib82e7fbc2017-01-06 11:41:41 -0800118 echo "RESULT: ${currentBuild.result}"
119 }
alshabib7f3be8d2016-09-27 18:04:56 -0700120
alshabib82e7fbc2017-01-06 11:41:41 -0800121 }
alshabib152823c2016-09-07 23:49:12 -0700122}