blob: 2ad2820eb43da4d17d1f1fe41e2f69af41d19645 [file] [log] [blame]
alshabib19302662017-01-05 14:27:41 -08001def filename = 'manifest-' + env.BRANCH_NAME + '.xml'
alshabib4e1c96e2016-09-28 16:26:24 -07002
alshabib19302662017-01-05 14:27:41 -08003timeout (time: 240) {
4 node ('build') {
5 stage 'Checkout cord repo'
6 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', manifestBranch: env.BRANCH_NAME, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
7
8 stage 'Generate and Copy Manifest file'
9 sh returnStdout: true, script: 'repo manifest -r -o ' + filename
10 sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp'
11
12 dir('build') {
13 stage 'Redeploy head node and Build Vagrant box'
14 try {
15 parallel(
16 maasOps: {
17 sh "maas login maas http://10.90.0.2/MAAS/api/2.0 ${apiKey}"
18 sh "maas maas machine release ${systemId}"
19
20 timeout(time: 15) {
21 waitUntil {
22 try {
23 sh "maas maas machine read ${systemId} | grep Ready"
24 return true
25 } catch (exception) {
26 return false
27 }
alshabibef069942016-09-09 17:08:36 -070028 }
29 }
alshabib4e1c96e2016-09-28 16:26:24 -070030
alshabib19302662017-01-05 14:27:41 -080031 sh 'maas maas machines allocate'
32 sh "maas maas machine deploy ${systemId}"
alshabib4e1c96e2016-09-28 16:26:24 -070033
alshabib19302662017-01-05 14:27:41 -080034 timeout(time: 30) {
35 waitUntil {
36 try {
37 sh "maas maas machine read ${systemId} | grep Deployed"
38 return true
39 } catch (exception) {
40 return false
41 }
alshabibef069942016-09-09 17:08:36 -070042 }
43 }
alshabib4e1c96e2016-09-28 16:26:24 -070044
alshabib19302662017-01-05 14:27:41 -080045 }, vagrantOps: {
46 sh 'vagrant up corddev'
47 }, failFast : true
48 )
alshabib4e1c96e2016-09-28 16:26:24 -070049
alshabib19302662017-01-05 14:27:41 -080050 stage 'Fetch CORD packages'
51 sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev'
alshabib4e1c96e2016-09-28 16:26:24 -070052
alshabib19302662017-01-05 14:27:41 -080053 stage 'Build CORD Images'
54 sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev'
alshabib61509fb2016-09-09 02:43:20 -070055
alshabib19302662017-01-05 14:27:41 -080056 stage 'Publish to headnode'
57 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 -070058
alshabib19302662017-01-05 14:27:41 -080059 stage 'Deploy'
60 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 -070061
alshabib19302662017-01-05 14:27:41 -080062 stage 'Power cycle compute nodes'
63 parallel(
64 compute_1: {
65 sh 'ipmitool -U admin -P admin -H 10.90.0.10 power cycle'
66 }, compute_2: {
67 sh 'ipmitool -U admin -P admin -H 10.90.0.11 power cycle'
68 }, failFast : true
69 )
alshabib7f3be8d2016-09-27 18:04:56 -070070
alshabib19302662017-01-05 14:27:41 -080071 stage 'Wait for compute nodes to get deployed'
72 sh 'ssh-keygen -f "/home/ubuntu/.ssh/known_hosts" -R 10.90.0.251'
73 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")
74 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"
75 timeout(time: 45) {
76 waitUntil {
77 try {
78 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()
79 return num == '2'
80 } catch (exception) {
81 return false
82 }
alshabib4e1c96e2016-09-28 16:26:24 -070083 }
84 }
alshabib4e1c96e2016-09-28 16:26:24 -070085
alshabib19302662017-01-05 14:27:41 -080086 stage 'Wait for computes nodes to be provisioned'
87 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()
88 timeout(time:45) {
89 waitUntil {
90 try {
91 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()
92 return out != ""
93 } catch (exception) {
94 return false
95 }
alshabib7f3be8d2016-09-27 18:04:56 -070096 }
97 }
alshabib19302662017-01-05 14:27:41 -080098
99 stage 'Trigger Build'
100 url = 'https://jenkins.opencord.org/job/release-build/job/' + env.BRANCH_NAME + '/build'
101 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
102
103 currentBuild.result = 'SUCCESS'
104 } catch (err) {
105 currentBuild.result = 'FAILURE'
106 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'cord-dev@opencord.org', sendToIndividuals: false])
107 } finally {
108 sh 'vagrant destroy -f corddev'
alshabib7f3be8d2016-09-27 18:04:56 -0700109 }
alshabib19302662017-01-05 14:27:41 -0800110 echo "RESULT: ${currentBuild.result}"
111 }
alshabib7f3be8d2016-09-27 18:04:56 -0700112
alshabib19302662017-01-05 14:27:41 -0800113 }
alshabib152823c2016-09-07 23:49:12 -0700114}