blob: f4eee1fa2063b7289703f57856256de1a6e28e8e [file] [log] [blame]
Larry Peterson2c24d892018-06-28 13:44:58 -07001import groovy.json.JsonSlurperClassic
2
3env.IGNORE_LIST = ["All-Users"]
4
5env.approvers = 'andy@opennetworking.org,llp@opennetworking.org'
6env.recipients = 'cord-discuss@opencord.org'
7
8@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
17}
18
19@NonCPS
20def jsonParseMap(def json) {
21 def j = json.minus(")]}'")
22 return new groovy.json.JsonSlurperClassic().parseText(j)
23}
24
25def createBranch(def proj, def branch, def parent) {
26 cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
27 sh returnStdout: true, script: cmd
28}
29
30int checkBranchExists(def proj) {
31 if (env.IGNORE_LIST.contains(proj)) {
32 return 0
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) {
37 createBranch(proj, env.BRANCH_NAME, 'master')
38 return 1
39 }
40 return 0
41}
42
43node ('master') {
44
45 stage 'Check and create support branches'
46 def url = 'https://gerrit.opencord.org/projects/?type=CODE'
47 def response = httpRequest url: url, validResponseCodes: '200'
48 def info = jsonParseList(response.content)
49 int created = 0
50 for (index = 0; index < info.size(); index++) {
51 created += checkBranchExists(info[index])
52 }
53
54 if (created == 0) {
55
56 def now = new Date()
57 def metadata = 'None'
58 branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC'))
59
60 stage 'Release?'
61 timeout(time: 12, unit: 'HOURS') {
62 mail to: env.approvers,
63 subject: "Job '${JOB_NAME}' is waiting up for promotion",
64 body: "Please go to ${BUILD_URL}input and promote or abort the release. It will timeout after 12 hours."
65 metadata = input id: 'release-build', message: 'Should I perform a release?',
66 parameters: [booleanParam(defaultValue: true,
67 description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'),
68 string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'llp,acb'
69 }
70
71 if (metadata['release_version'] == 'None') {
72 error 'Release version cannot be None'
73 }
74
75 stage 'Create new manifest branch'
76 createBranch('manifest', metadata['release_version'], env.BRANCH_NAME)
77 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']]]
78 sh returnStdout: true, script: 'git checkout ' + metadata['release_version']
79 sh returnStdout: true, script: 'git pull origin ' + metadata['release_version']
80 sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
81
82 sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"'
83 sh returnStdout: true, script: 'git push origin ' + metadata['release_version']
84
85 stage 'Build and Release ONOS applications'
86
87 if (metadata['build_onos_apps']) {
88 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true,
89 manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos',
90 manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
91 if (env.BRANCH_NAME == 'master') {
92 sh returnStdout: true, script: 'cd onos-apps/apps && mvn clean deploy'
93 } else {
94 sh returnStdout: true, script: 'cd onos-apps/apps && mvn -Prelease clean deploy'
95 }
96 }
97
98 mail to: env.recipients,
99 subject: 'Nightly bleeding edge ' + metadata['release_version'] + ' released',
100 replyTo: 'cord-dev@opencord.org',
101 body: '''Hi CORD Community,
102
103 |A new bleeding edge version of cord is available, feel free to test it.
104 |You can obtain it using the following commands:
105
106 |repo init -u https://gerrit.opencord.org/manifest -b '''.stripMargin() + metadata['release_version'] + '''
107 |repo sync
108
109 |Have fun!
110
111 |--
112 |CORD Automated Release
113 '''.stripMargin()
114 }
115}