blob: 4d4dce6b5f0022448a75fcf3253229c7396d5cd5 [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
27def checkBranchExists(def proj) {
alshabib47b75c62017-01-03 10:04:26 -080028 if (env.IGNORE_LIST.contains(proj)) {
29 return
30 }
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')
alshabib47b75c62017-01-03 10:04:26 -080035 }
36}
37
38node ('master') {
alshabibf36a8732017-01-03 21:23:11 -080039 stage 'Release?'
alshabib929ec0d2017-01-04 14:49:51 -080040 mail to: 'ali@onlab.us',
41 subject: "Job '${JOB_NAME}' is waiting up for promotion",
42 body: "Please go to ${BUILD_URL}input and promote or abort the release"
alshabibf36a8732017-01-03 21:23:11 -080043 def metadata = input id: 'release-build', message: 'Should I perform a release?', parameters: [booleanParam(defaultValue: true, description: 'Build and release onos applications', name: 'build_onos_apps'), string(defaultValue: 'None', description: '', name: 'release_version')], submitter: 'ash'
alshabib47b75c62017-01-03 10:04:26 -080044
alshabib35069d42017-01-04 14:58:34 -080045 if (metadata['release_version'] == 'None') {
46 error 'Release version cannot be None'
47 }
48
alshabibf36a8732017-01-03 21:23:11 -080049 stage 'Check and create support branches'
alshabib47b75c62017-01-03 10:04:26 -080050 def url = 'https://gerrit.opencord.org/projects/?type=CODE'
51 def response = httpRequest url: url, validResponseCodes: '200'
52 def info = jsonParseList(response.content)
53 for (index = 0; index < info.size(); index++) {
54 checkBranchExists(info[index])
55 }
alshabibf36a8732017-01-03 21:23:11 -080056
alshabiba2c83c92017-01-03 23:09:48 -080057 stage 'Create new manifest branch'
58 createBranch('manifest', metadata['release_version'], env.BRANCH_NAME)
59 checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: metadata['release_version'] ]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'dd9d4677-2415-4f82-8e79-99dcd530f023', url: 'ssh://jenkins@gerrit.opencord.org:29418/manifest']]]
alshabib6df698f2017-01-03 23:26:10 -080060 sh returnStdout: true, script: 'git checkout ' + metadata['release_version']
alshabib226e4db2017-01-03 23:21:31 -080061 sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
alshabib929ec0d2017-01-04 14:49:51 -080062 //TODO push new bits to manifest repo
63
64 //TODO build and release onos apps
alshabib47b75c62017-01-03 10:04:26 -080065}