blob: ca2fa77f797cb15627d02dbec9f3e3f6c1495087 [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
alshabib47b75c62017-01-03 10:04:26 -08005@NonCPS
6def jsonParseList(def json) {
7 j = json.minus(")]}'")
8 resp = new groovy.json.JsonSlurperClassic().parseText(j)
9 list = []
10 for (i in resp.keySet()) {
11 list << i
12 }
13 return list
alshabib8b389f22017-01-03 09:52:23 -080014}
15
alshabib47b75c62017-01-03 10:04:26 -080016@NonCPS
17def jsonParseMap(def json) {
18 def j = json.minus(")]}'")
19 return new groovy.json.JsonSlurperClassic().parseText(j)
20}
21
alshabiba2c83c92017-01-03 23:09:48 -080022def createBranch(def proj, def branch, def parent) {
23 cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
alshabib47b75c62017-01-03 10:04:26 -080024 sh returnStdout: true, script: cmd
25}
26
alshabib9b25b612017-01-04 16:42:54 -080027int checkBranchExists(def proj) {
alshabib47b75c62017-01-03 10:04:26 -080028 if (env.IGNORE_LIST.contains(proj)) {
alshabib9b25b612017-01-04 16:42:54 -080029 return 0
alshabib47b75c62017-01-03 10:04:26 -080030 }
31 url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + env.BRANCH_NAME
32 response = httpRequest url: url, validResponseCodes: '200,404'
33 if (response.status == 404) {
alshabiba2c83c92017-01-03 23:09:48 -080034 createBranch(proj, env.BRANCH_NAME, 'master')
alshabibb08bbc02017-01-04 16:26:52 -080035 return 1
alshabib47b75c62017-01-03 10:04:26 -080036 }
alshabibb08bbc02017-01-04 16:26:52 -080037 return 0
alshabib47b75c62017-01-03 10:04:26 -080038}
39
40node ('master') {
alshabib35069d42017-01-04 14:58:34 -080041
alshabibf36a8732017-01-03 21:23:11 -080042 stage 'Check and create support branches'
alshabib47b75c62017-01-03 10:04:26 -080043 def url = 'https://gerrit.opencord.org/projects/?type=CODE'
44 def response = httpRequest url: url, validResponseCodes: '200'
45 def info = jsonParseList(response.content)
alshabib9b25b612017-01-04 16:42:54 -080046 int created = 0
alshabib47b75c62017-01-03 10:04:26 -080047 for (index = 0; index < info.size(); index++) {
alshabib9b25b612017-01-04 16:42:54 -080048 created += checkBranchExists(info[index])
alshabib47b75c62017-01-03 10:04:26 -080049 }
alshabibf36a8732017-01-03 21:23:11 -080050
alshabibb08bbc02017-01-04 16:26:52 -080051 if (created == 0) {
52
53 stage 'Release?'
54 mail to: 'ali@onlab.us',
55 subject: "Job '${JOB_NAME}' is waiting up for promotion",
56 body: "Please go to ${BUILD_URL}input and promote or abort the release"
57 def metadata = input id: 'release-build', message: 'Should I perform a release?',
58 parameters: [booleanParam(defaultValue: true,
59 description: 'Build and release onos applications', name: 'build_onos_apps'),
60 string(defaultValue: 'None', description: '', name: 'release_version')], submitter: 'ash'
61
62 if (metadata['release_version'] == 'None') {
63 error 'Release version cannot be None'
64 }
65
66 stage 'Create new manifest branch'
67 createBranch('manifest', metadata['release_version'], env.BRANCH_NAME)
68 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']]]
69 sh returnStdout: true, script: 'git checkout ' + metadata['release_version']
70 sh returnStdout: true, script: 'git pull origin ' + metadata['release_version']
71 sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
alshabibea397b52017-01-04 15:08:19 -080072
alshabibb08bbc02017-01-04 16:26:52 -080073 sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"'
74 sh returnStdout: true, script: 'git push origin ' + metadata['release_version']
alshabib3e20e822017-01-04 15:02:16 -080075
alshabib929ec0d2017-01-04 14:49:51 -080076 //TODO build and release onos apps
alshabibb08bbc02017-01-04 16:26:52 -080077
78 }
alshabib47b75c62017-01-03 10:04:26 -080079}