blob: 58ab88c33e262a0f1aab14a1b867355e22e53ebe [file] [log] [blame]
alshabib47b75c62017-01-03 10:04:26 -08001import groovy.json.JsonSlurperClassic
alshabib8b389f22017-01-03 09:52:23 -08002
alshabib47b75c62017-01-03 10:04:26 -08003env.IGNORE_LIST = ["All-Users"]
alshabib8b389f22017-01-03 09:52:23 -08004
alshabib4c6a1602017-01-06 11:40:25 -08005env.approvers = 'ali@onlab.us,andy@onlab.us, llp@onlab.us'
alshabibb915d422017-01-22 16:19:17 -08006env.recipients = 'cord-discuss@opencord.org'
alshabib4c6a1602017-01-06 11:40:25 -08007
alshabib47b75c62017-01-03 10:04:26 -08008@NonCPS
9def 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
alshabib8b389f22017-01-03 09:52:23 -080017}
18
alshabib47b75c62017-01-03 10:04:26 -080019@NonCPS
20def jsonParseMap(def json) {
21 def j = json.minus(")]}'")
22 return new groovy.json.JsonSlurperClassic().parseText(j)
23}
24
alshabiba2c83c92017-01-03 23:09:48 -080025def createBranch(def proj, def branch, def parent) {
26 cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
alshabib47b75c62017-01-03 10:04:26 -080027 sh returnStdout: true, script: cmd
28}
29
alshabib9b25b612017-01-04 16:42:54 -080030int checkBranchExists(def proj) {
alshabib47b75c62017-01-03 10:04:26 -080031 if (env.IGNORE_LIST.contains(proj)) {
alshabib9b25b612017-01-04 16:42:54 -080032 return 0
alshabib47b75c62017-01-03 10:04:26 -080033 }
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) {
alshabiba2c83c92017-01-03 23:09:48 -080037 createBranch(proj, env.BRANCH_NAME, 'master')
alshabibb08bbc02017-01-04 16:26:52 -080038 return 1
alshabib47b75c62017-01-03 10:04:26 -080039 }
alshabibb08bbc02017-01-04 16:26:52 -080040 return 0
alshabib47b75c62017-01-03 10:04:26 -080041}
42
43node ('master') {
alshabib35069d42017-01-04 14:58:34 -080044
alshabibf36a8732017-01-03 21:23:11 -080045 stage 'Check and create support branches'
alshabib47b75c62017-01-03 10:04:26 -080046 def url = 'https://gerrit.opencord.org/projects/?type=CODE'
47 def response = httpRequest url: url, validResponseCodes: '200'
48 def info = jsonParseList(response.content)
alshabib9b25b612017-01-04 16:42:54 -080049 int created = 0
alshabib47b75c62017-01-03 10:04:26 -080050 for (index = 0; index < info.size(); index++) {
alshabib9b25b612017-01-04 16:42:54 -080051 created += checkBranchExists(info[index])
alshabib47b75c62017-01-03 10:04:26 -080052 }
alshabibf36a8732017-01-03 21:23:11 -080053
alshabibb08bbc02017-01-04 16:26:52 -080054 if (created == 0) {
55
alshabib4c6a1602017-01-06 11:40:25 -080056 def now = new Date()
57 branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC'))
58
alshabibb08bbc02017-01-04 16:26:52 -080059 stage 'Release?'
alshabibb915d422017-01-22 16:19:17 -080060 timeout(time: 12, unit: 'HOURS') {
61 mail to: env.approvers,
62 subject: "Job '${JOB_NAME}' is waiting up for promotion",
63 body: "Please go to ${BUILD_URL}input and promote or abort the release. It will timeout after 12 hours."
64 def metadata = input id: 'release-build', message: 'Should I perform a release?',
65 parameters: [booleanParam(defaultValue: true,
66 description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'),
67 string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'ash,llp,acb'
68 }
alshabibb08bbc02017-01-04 16:26:52 -080069
70 if (metadata['release_version'] == 'None') {
71 error 'Release version cannot be None'
72 }
73
74 stage 'Create new manifest branch'
75 createBranch('manifest', metadata['release_version'], env.BRANCH_NAME)
76 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']]]
77 sh returnStdout: true, script: 'git checkout ' + metadata['release_version']
78 sh returnStdout: true, script: 'git pull origin ' + metadata['release_version']
79 sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
alshabibea397b52017-01-04 15:08:19 -080080
alshabibb08bbc02017-01-04 16:26:52 -080081 sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"'
82 sh returnStdout: true, script: 'git push origin ' + metadata['release_version']
alshabib4c6a1602017-01-06 11:40:25 -080083
84 stage 'Build and Release ONOS applications'
alshabib1fca2d72017-01-04 17:10:13 -080085
86 if (metadata['build_onos_apps']) {
87 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true,
alshabib7d2e14a2017-01-04 17:11:44 -080088 manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos',
alshabib1fca2d72017-01-04 17:10:13 -080089 manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
alshabib4c6a1602017-01-06 11:40:25 -080090 if (env.BRANCH_NAME == 'master') {
91 sh returnStdout: true, script: 'cd onos-apps/apps && mvn clean deploy'
92 } else {
93 sh returnStdout: true, script: 'cd onos-apps/apps && mvn -Prelease clean deploy'
94 }
alshabib1fca2d72017-01-04 17:10:13 -080095 }
alshabibb08bbc02017-01-04 16:26:52 -080096
alshabib4c6a1602017-01-06 11:40:25 -080097 mail to: env.recipients,
alshabibf66333a2017-01-07 09:51:38 -080098 subject: metadata['release_version'] + ' released',
alshabib4c6a1602017-01-06 11:40:25 -080099 replyTo: 'cord-discuss@opencord.org',
100 body: '''Hi CORD Community,
101
alshabibaac262b2017-01-06 15:15:08 -0800102 |A new version of cord is available, feel free to test it.
alshabib4c6a1602017-01-06 11:40:25 -0800103 |You can obtain it using the following commands:
104
105 |repo init -u https://gerrit.opencord.org/manifest -b '''.stripMargin() + metadata['release_version'] + '''
106 |repo sync
107
108 |Have fun!
109
110 |--
111 |CORD Automated Release
112 '''.stripMargin()
alshabibb08bbc02017-01-04 16:26:52 -0800113 }
alshabib47b75c62017-01-03 10:04:26 -0800114}