alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 1 | import groovy.json.JsonSlurperClassic |
alshabib | 8b389f2 | 2017-01-03 09:52:23 -0800 | [diff] [blame] | 2 | |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 3 | env.IGNORE_LIST = ["All-Users"] |
alshabib | 9213b08 | 2017-01-03 13:39:59 -0800 | [diff] [blame] | 4 | |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 5 | env.approvers = 'ali@onlab.us' |
| 6 | env.recipients = 'ali@onlab.us' |
| 7 | |
alshabib | 0029418 | 2017-01-03 17:52:16 -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 | 0029418 | 2017-01-03 17:52:16 -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 | a871362 | 2017-01-05 13:49:43 -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 | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 27 | sh returnStdout: true, script: cmd |
| 28 | } |
| 29 | |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 30 | int checkBranchExists(def proj) { |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 31 | if (env.IGNORE_LIST.contains(proj)) { |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 32 | return 0 |
alshabib | 0029418 | 2017-01-03 17:52:16 -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 | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 37 | createBranch(proj, env.BRANCH_NAME, 'master') |
| 38 | return 1 |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 39 | } |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 40 | return 0 |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | node ('master') { |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 44 | |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 45 | stage 'Check and create support branches' |
alshabib | 0029418 | 2017-01-03 17:52:16 -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 | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 49 | int created = 0 |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 50 | for (index = 0; index < info.size(); index++) { |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 51 | created += checkBranchExists(info[index]) |
| 52 | } |
| 53 | |
| 54 | if (created == 0) { |
| 55 | |
| 56 | def now = new Date() |
alshabib | 34408b0 | 2017-01-05 13:53:30 -0800 | [diff] [blame] | 57 | branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC')) |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 58 | |
| 59 | stage 'Release?' |
| 60 | mail to: env.approvers, |
| 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, |
| 65 | description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'), |
| 66 | string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'ash' |
| 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' |
| 78 | |
| 79 | sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"' |
| 80 | sh returnStdout: true, script: 'git push origin ' + metadata['release_version'] |
| 81 | |
| 82 | stage 'Build and Release ONOS applications' |
| 83 | |
| 84 | if (metadata['build_onos_apps']) { |
| 85 | checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, |
| 86 | manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos', |
| 87 | manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true] |
| 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 | } |
| 93 | } |
| 94 | |
| 95 | mail to: env.recipients, |
alshabib | e897629 | 2017-01-05 13:51:33 -0800 | [diff] [blame] | 96 | subject: 'Nightly bleeding edge ' + branch + ' released', |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 97 | replyTo: 'cord-discuss@opencord.org', |
| 98 | body: '''Hi CORD Community, |
| 99 | |
alshabib | 32c5e9a | 2017-01-05 14:00:37 -0800 | [diff] [blame] | 100 | |A new bleeding edge version of cord is available, feel free to test it. |
| 101 | |You can obtain it using the following commands: |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 102 | |
alshabib | 0485de1 | 2017-01-05 14:10:58 -0800 | [diff] [blame^] | 103 | |repo init -u https://gerrit.opencord.org/manifest -b ''' + metadata['release_version'] + ''' |
alshabib | 32c5e9a | 2017-01-05 14:00:37 -0800 | [diff] [blame] | 104 | |repo sync |
alshabib | a871362 | 2017-01-05 13:49:43 -0800 | [diff] [blame] | 105 | |
alshabib | 32c5e9a | 2017-01-05 14:00:37 -0800 | [diff] [blame] | 106 | |-- |
| 107 | |CORD Automated Release |
| 108 | '''.stripMargin() |
alshabib | 0029418 | 2017-01-03 17:52:16 -0800 | [diff] [blame] | 109 | } |
| 110 | } |