blob: a495b7a20c7f31a3a4808330e2dac8f35a5d868a [file] [log] [blame]
alshabib00294182017-01-03 17:52:16 -08001import 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
alshabiba8713622017-01-05 13:49:43 -08005env.approvers = 'ali@onlab.us'
6env.recipients = 'ali@onlab.us'
7
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
alshabib00294182017-01-03 17:52:16 -080027 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()
alshabib34408b02017-01-05 13:53:30 -080057 branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC'))
alshabiba8713622017-01-05 13:49:43 -080058
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,
alshabibe8976292017-01-05 13:51:33 -080096 subject: 'Nightly bleeding edge ' + branch + ' released',
alshabiba8713622017-01-05 13:49:43 -080097 replyTo: 'cord-discuss@opencord.org',
98 body: '''Hi CORD Community,
99
alshabib32c5e9a2017-01-05 14:00:37 -0800100 |A new bleeding edge version of cord is available, feel free to test it.
101 |You can obtain it using the following commands:
alshabiba8713622017-01-05 13:49:43 -0800102
alshabib32c5e9a2017-01-05 14:00:37 -0800103 |repo init -u https://gerrit.opencord.org/manifest -b ${metadata['release_version']}
104 |repo sync
alshabiba8713622017-01-05 13:49:43 -0800105
alshabib32c5e9a2017-01-05 14:00:37 -0800106 |--
107 |CORD Automated Release
108 '''.stripMargin()
alshabib00294182017-01-03 17:52:16 -0800109 }
110}