alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 1 | import groovy.json.JsonSlurperClassic |
alshabib | 8b389f2 | 2017-01-03 09:52:23 -0800 | [diff] [blame] | 2 | |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 3 | env.IGNORE_LIST = ["All-Users"] |
alshabib | 8b389f2 | 2017-01-03 09:52:23 -0800 | [diff] [blame] | 4 | |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 5 | env.approvers = 'ali@onlab.us,andy@onlab.us, llp@onlab.us' |
| 6 | env.recipients = 'ali@onlab.us,andy@onlab.us, llp@onlab.us' |
| 7 | |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 8 | @NonCPS |
| 9 | def jsonParseList(def json) { |
| 10 | j = json.minus(")]}'") |
| 11 | resp = new groovy.json.JsonSlurperClassic().parseText(j) |
| 12 | list = [] |
| 13 | for (i in resp.keySet()) { |
| 14 | list << i |
| 15 | } |
| 16 | return list |
alshabib | 8b389f2 | 2017-01-03 09:52:23 -0800 | [diff] [blame] | 17 | } |
| 18 | |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 19 | @NonCPS |
| 20 | def jsonParseMap(def json) { |
| 21 | def j = json.minus(")]}'") |
| 22 | return new groovy.json.JsonSlurperClassic().parseText(j) |
| 23 | } |
| 24 | |
alshabib | a2c83c9 | 2017-01-03 23:09:48 -0800 | [diff] [blame] | 25 | def createBranch(def proj, def branch, def parent) { |
| 26 | cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 27 | sh returnStdout: true, script: cmd |
| 28 | } |
| 29 | |
alshabib | 9b25b61 | 2017-01-04 16:42:54 -0800 | [diff] [blame] | 30 | int checkBranchExists(def proj) { |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 31 | if (env.IGNORE_LIST.contains(proj)) { |
alshabib | 9b25b61 | 2017-01-04 16:42:54 -0800 | [diff] [blame] | 32 | return 0 |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 33 | } |
| 34 | url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + env.BRANCH_NAME |
| 35 | response = httpRequest url: url, validResponseCodes: '200,404' |
| 36 | if (response.status == 404) { |
alshabib | a2c83c9 | 2017-01-03 23:09:48 -0800 | [diff] [blame] | 37 | createBranch(proj, env.BRANCH_NAME, 'master') |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 38 | return 1 |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 39 | } |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 40 | return 0 |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | node ('master') { |
alshabib | 35069d4 | 2017-01-04 14:58:34 -0800 | [diff] [blame] | 44 | |
alshabib | f36a873 | 2017-01-03 21:23:11 -0800 | [diff] [blame] | 45 | stage 'Check and create support branches' |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 46 | def url = 'https://gerrit.opencord.org/projects/?type=CODE' |
| 47 | def response = httpRequest url: url, validResponseCodes: '200' |
| 48 | def info = jsonParseList(response.content) |
alshabib | 9b25b61 | 2017-01-04 16:42:54 -0800 | [diff] [blame] | 49 | int created = 0 |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 50 | for (index = 0; index < info.size(); index++) { |
alshabib | 9b25b61 | 2017-01-04 16:42:54 -0800 | [diff] [blame] | 51 | created += checkBranchExists(info[index]) |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 52 | } |
alshabib | f36a873 | 2017-01-03 21:23:11 -0800 | [diff] [blame] | 53 | |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 54 | if (created == 0) { |
| 55 | |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 56 | def now = new Date() |
| 57 | branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC')) |
| 58 | |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 59 | stage 'Release?' |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 60 | mail to: env.approvers, |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 61 | subject: "Job '${JOB_NAME}' is waiting up for promotion", |
| 62 | body: "Please go to ${BUILD_URL}input and promote or abort the release" |
| 63 | def metadata = input id: 'release-build', message: 'Should I perform a release?', |
| 64 | parameters: [booleanParam(defaultValue: true, |
alshabib | 1fca2d7 | 2017-01-04 17:10:13 -0800 | [diff] [blame] | 65 | description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'), |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 66 | string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'ash,llp,acb' |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 67 | |
| 68 | if (metadata['release_version'] == 'None') { |
| 69 | error 'Release version cannot be None' |
| 70 | } |
| 71 | |
| 72 | stage 'Create new manifest branch' |
| 73 | createBranch('manifest', metadata['release_version'], env.BRANCH_NAME) |
| 74 | checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: metadata['release_version'] ]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'WipeWorkspace'], [$class: 'CleanBeforeCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'dd9d4677-2415-4f82-8e79-99dcd530f023', url: 'ssh://jenkins@gerrit.opencord.org:29418/manifest']]] |
| 75 | sh returnStdout: true, script: 'git checkout ' + metadata['release_version'] |
| 76 | sh returnStdout: true, script: 'git pull origin ' + metadata['release_version'] |
| 77 | sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml' |
alshabib | ea397b5 | 2017-01-04 15:08:19 -0800 | [diff] [blame] | 78 | |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 79 | sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"' |
| 80 | sh returnStdout: true, script: 'git push origin ' + metadata['release_version'] |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 81 | |
| 82 | stage 'Build and Release ONOS applications' |
alshabib | 1fca2d7 | 2017-01-04 17:10:13 -0800 | [diff] [blame] | 83 | |
| 84 | if (metadata['build_onos_apps']) { |
| 85 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, |
alshabib | 7d2e14a | 2017-01-04 17:11:44 -0800 | [diff] [blame] | 86 | manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos', |
alshabib | 1fca2d7 | 2017-01-04 17:10:13 -0800 | [diff] [blame] | 87 | manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true] |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 88 | if (env.BRANCH_NAME == 'master') { |
| 89 | sh returnStdout: true, script: 'cd onos-apps/apps && mvn clean deploy' |
| 90 | } else { |
| 91 | sh returnStdout: true, script: 'cd onos-apps/apps && mvn -Prelease clean deploy' |
| 92 | } |
alshabib | 1fca2d7 | 2017-01-04 17:10:13 -0800 | [diff] [blame] | 93 | } |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 94 | |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 95 | mail to: env.recipients, |
| 96 | subject: branch + ' released', |
| 97 | replyTo: 'cord-discuss@opencord.org', |
| 98 | body: '''Hi CORD Community, |
| 99 | |
alshabib | aac262b | 2017-01-06 15:15:08 -0800 | [diff] [blame^] | 100 | |A new version of cord is available, feel free to test it. |
alshabib | 4c6a160 | 2017-01-06 11:40:25 -0800 | [diff] [blame] | 101 | |You can obtain it using the following commands: |
| 102 | |
| 103 | |repo init -u https://gerrit.opencord.org/manifest -b '''.stripMargin() + metadata['release_version'] + ''' |
| 104 | |repo sync |
| 105 | |
| 106 | |Have fun! |
| 107 | |
| 108 | |-- |
| 109 | |CORD Automated Release |
| 110 | '''.stripMargin() |
alshabib | b08bbc0 | 2017-01-04 16:26:52 -0800 | [diff] [blame] | 111 | } |
alshabib | 47b75c6 | 2017-01-03 10:04:26 -0800 | [diff] [blame] | 112 | } |