blob: f4eee1fa2063b7289703f57856256de1a6e28e8e [file] [log] [blame]
Zack Williams3ed9f712017-05-03 12:29:17 -07001import groovy.json.JsonSlurperClassic
alshabib8b389f22017-01-03 09:52:23 -08002
alshabib00294182017-01-03 17:52:16 -08003env.IGNORE_LIST = ["All-Users"]
alshabib9213b082017-01-03 13:39:59 -08004
Andy Bavier16574df2017-09-22 08:05:53 -07005env.approvers = 'andy@opennetworking.org,llp@opennetworking.org'
alshabib44c5f4c2017-01-22 16:20:56 -08006env.recipients = 'cord-discuss@opencord.org'
alshabiba8713622017-01-05 13:49:43 -08007
alshabib00294182017-01-03 17:52:16 -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
alshabib00294182017-01-03 17:52:16 -080019@NonCPS
20def jsonParseMap(def json) {
21 def j = json.minus(")]}'")
22 return new groovy.json.JsonSlurperClassic().parseText(j)
23}
24
alshabiba8713622017-01-05 13:49:43 -080025def createBranch(def proj, def branch, def parent) {
26 cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
Zack Williams3ed9f712017-05-03 12:29:17 -070027 sh returnStdout: true, script: cmd
28}
29
alshabiba8713622017-01-05 13:49:43 -080030int checkBranchExists(def proj) {
alshabib00294182017-01-03 17:52:16 -080031 if (env.IGNORE_LIST.contains(proj)) {
alshabiba8713622017-01-05 13:49:43 -080032 return 0
alshabib00294182017-01-03 17:52:16 -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) {
alshabiba8713622017-01-05 13:49:43 -080037 createBranch(proj, env.BRANCH_NAME, 'master')
38 return 1
alshabib00294182017-01-03 17:52:16 -080039 }
alshabiba8713622017-01-05 13:49:43 -080040 return 0
alshabib00294182017-01-03 17:52:16 -080041}
42
43node ('master') {
alshabib00294182017-01-03 17:52:16 -080044
alshabiba8713622017-01-05 13:49:43 -080045 stage 'Check and create support branches'
alshabib00294182017-01-03 17:52:16 -080046 def url = 'https://gerrit.opencord.org/projects/?type=CODE'
47 def response = httpRequest url: url, validResponseCodes: '200'
48 def info = jsonParseList(response.content)
alshabiba8713622017-01-05 13:49:43 -080049 int created = 0
alshabib00294182017-01-03 17:52:16 -080050 for (index = 0; index < info.size(); index++) {
alshabiba8713622017-01-05 13:49:43 -080051 created += checkBranchExists(info[index])
52 }
53
54 if (created == 0) {
55
56 def now = new Date()
alshabibf620b0a2017-01-27 06:42:53 -080057 def metadata = 'None'
alshabib34408b02017-01-05 13:53:30 -080058 branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC'))
alshabiba8713622017-01-05 13:49:43 -080059
60 stage 'Release?'
alshabib44c5f4c2017-01-22 16:20:56 -080061 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."
alshabibf620b0a2017-01-27 06:42:53 -080065 metadata = input id: 'release-build', message: 'Should I perform a release?',
alshabib44c5f4c2017-01-22 16:20:56 -080066 parameters: [booleanParam(defaultValue: true,
Zack Williams3ed9f712017-05-03 12:29:17 -070067 description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'),
Andy Bavier16574df2017-09-22 08:05:53 -070068 string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'llp,acb'
alshabib44c5f4c2017-01-22 16:20:56 -080069 }
alshabiba8713622017-01-05 13:49:43 -080070
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']
Zack Williams3ed9f712017-05-03 12:29:17 -070080 sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
81
alshabiba8713622017-01-05 13:49:43 -080082 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'
Zack Williams3ed9f712017-05-03 12:29:17 -070086
alshabiba8713622017-01-05 13:49:43 -080087 if (metadata['build_onos_apps']) {
Zack Williams3ed9f712017-05-03 12:29:17 -070088 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true,
89 manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos',
alshabiba8713622017-01-05 13:49:43 -080090 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,
alshabib9d007ba2017-01-07 09:50:50 -080099 subject: 'Nightly bleeding edge ' + metadata['release_version'] + ' released',
alshabib53925862017-01-06 15:20:46 -0800100 replyTo: 'cord-dev@opencord.org',
alshabiba8713622017-01-05 13:49:43 -0800101 body: '''Hi CORD Community,
102
Zack Williams3ed9f712017-05-03 12:29:17 -0700103 |A new bleeding edge version of cord is available, feel free to test it.
alshabib32c5e9a2017-01-05 14:00:37 -0800104 |You can obtain it using the following commands:
alshabiba8713622017-01-05 13:49:43 -0800105
alshabib360a70d2017-01-05 14:13:03 -0800106 |repo init -u https://gerrit.opencord.org/manifest -b '''.stripMargin() + metadata['release_version'] + '''
alshabib32c5e9a2017-01-05 14:00:37 -0800107 |repo sync
alshabiba8713622017-01-05 13:49:43 -0800108
alshabiba1f97eb2017-01-05 14:16:13 -0800109 |Have fun!
110
alshabib32c5e9a2017-01-05 14:00:37 -0800111 |--
112 |CORD Automated Release
113 '''.stripMargin()
alshabib00294182017-01-03 17:52:16 -0800114 }
115}