alshabib | 08d0a1f | 2017-01-05 15:04:28 -0800 | [diff] [blame] | 1 | def filename = 'manifest-${branch}.xml' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 2 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 3 | timeout (time: 240) { |
| 4 | node ('build') { |
| 5 | stage 'Checkout cord repo' |
alshabib | 513ca14 | 2017-01-05 15:06:24 -0800 | [diff] [blame^] | 6 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true] |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 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 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 28 | } |
| 29 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 30 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 31 | sh 'maas maas machines allocate' |
| 32 | sh "maas maas machine deploy ${systemId}" |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 33 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 34 | 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 | } |
alshabib | ef06994 | 2016-09-09 17:08:36 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 44 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 45 | }, vagrantOps: { |
| 46 | sh 'vagrant up corddev' |
| 47 | }, failFast : true |
| 48 | ) |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 49 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 50 | stage 'Fetch CORD packages' |
| 51 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew fetch" corddev' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 52 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 53 | stage 'Build CORD Images' |
| 54 | sh 'vagrant ssh -c "cd /cord/build; ./gradlew buildImages" corddev' |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 55 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 56 | 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' |
alshabib | 61509fb | 2016-09-09 02:43:20 -0700 | [diff] [blame] | 58 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 59 | 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' |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 61 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 62 | 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 | ) |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 70 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 71 | 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 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
alshabib | 4e1c96e | 2016-09-28 16:26:24 -0700 | [diff] [blame] | 85 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 86 | 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 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 98 | |
| 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' |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 109 | } |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 110 | echo "RESULT: ${currentBuild.result}" |
| 111 | } |
alshabib | 7f3be8d | 2016-09-27 18:04:56 -0700 | [diff] [blame] | 112 | |
alshabib | 1930266 | 2017-01-05 14:27:41 -0800 | [diff] [blame] | 113 | } |
alshabib | 152823c | 2016-09-07 23:49:12 -0700 | [diff] [blame] | 114 | } |