blob: ae8863f2de48c072d1753061e5b633f2414fff52 [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) {
12 node ('build') {
13 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: {
21 sh "maas login maas http://10.90.0.2/MAAS/api/2.0 ${apiKey}"
22 sh "maas maas machine release ${systemId}"
23
24 timeout(time: 15) {
25 waitUntil {
26 try {
27 sh "maas maas machine read ${systemId} | grep Ready"
28 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'
36 sh "maas maas machine deploy ${systemId}"
alshabib4e1c96e2016-09-28 16:26:24 -070037
alshabib19302662017-01-05 14:27:41 -080038 timeout(time: 30) {
39 waitUntil {
40 try {
41 sh "maas maas machine read ${systemId} | grep Deployed"
42 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
alshabib19302662017-01-05 14:27:41 -080060 stage 'Publish to headnode'
61 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=10.90.0.251:5000 -PdeployConfig=config/onlab_develop_pod.yml publish" corddev'
alshabib61509fb2016-09-09 02:43:20 -070062
alshabib19302662017-01-05 14:27:41 -080063 stage 'Deploy'
64 sh 'vagrant ssh -c "cd /cord/build; ./gradlew -PtargetReg=10.90.0.251:5000 -PdeployConfig=config/onlab_develop_pod.yml deploy" corddev'
alshabib4e1c96e2016-09-28 16:26:24 -070065
alshabib19302662017-01-05 14:27:41 -080066 stage 'Power cycle compute nodes'
67 parallel(
68 compute_1: {
69 sh 'ipmitool -U admin -P admin -H 10.90.0.10 power cycle'
70 }, compute_2: {
71 sh 'ipmitool -U admin -P admin -H 10.90.0.11 power cycle'
72 }, failFast : true
73 )
alshabib7f3be8d2016-09-27 18:04:56 -070074
alshabib19302662017-01-05 14:27:41 -080075 stage 'Wait for compute nodes to get deployed'
76 sh 'ssh-keygen -f "/home/ubuntu/.ssh/known_hosts" -R 10.90.0.251'
77 def cordapikey = sh(returnStdout: true, script: "sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 sudo maas-region-admin apikey --username cord")
78 sh "sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 maas login pod-maas http://10.90.0.251/MAAS/api/1.0 $cordapikey"
79 timeout(time: 45) {
80 waitUntil {
81 try {
82 num = sh(returnStdout: true, script: "sshpass -p ${headnodepass} ssh -l ${headnodeuser} 10.90.0.251 maas pod-maas nodes list | grep Deployed | wc -l").trim()
83 return num == '2'
84 } catch (exception) {
85 return false
86 }
alshabib4e1c96e2016-09-28 16:26:24 -070087 }
88 }
alshabib4e1c96e2016-09-28 16:26:24 -070089
alshabib19302662017-01-05 14:27:41 -080090 stage 'Wait for computes nodes to be provisioned'
91 ip = sh (returnStdout: true, script:"sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim()
92 timeout(time:45) {
93 waitUntil {
94 try {
95 out = sh (returnStdout: true, script:"sshpass -p ${headnodepass} ssh -oStrictHostKeyChecking=no -l ${headnodeuser} 10.90.0.251 curl -sS http://$ip:4243/provision/ | jq -c '.[] | select(.status | contains(2))'").trim()
96 return out != ""
97 } catch (exception) {
98 return false
99 }
alshabib7f3be8d2016-09-27 18:04:56 -0700100 }
101 }
alshabib19302662017-01-05 14:27:41 -0800102
103 stage 'Trigger Build'
alshabib0e388542017-01-06 11:40:58 -0800104 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
alshabib19302662017-01-05 14:27:41 -0800105 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
106
107 currentBuild.result = 'SUCCESS'
108 } catch (err) {
109 currentBuild.result = 'FAILURE'
110 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'cord-dev@opencord.org', sendToIndividuals: false])
111 } finally {
112 sh 'vagrant destroy -f corddev'
alshabib7f3be8d2016-09-27 18:04:56 -0700113 }
alshabib19302662017-01-05 14:27:41 -0800114 echo "RESULT: ${currentBuild.result}"
115 }
alshabib7f3be8d2016-09-27 18:04:56 -0700116
alshabib19302662017-01-05 14:27:41 -0800117 }
alshabib152823c2016-09-07 23:49:12 -0700118}