blob: 5d1dd0ec6c8cef3c8ba102c634133200c3d329e1 [file] [log] [blame]
Jakub Josefc5a223a2017-03-01 14:40:08 +01001def common = new com.mirantis.mk.Common()
2def aptly = new com.mirantis.mk.Aptly()
chnyda6a3553e2017-03-21 13:20:15 +01003
4
5def packages
6try {
7 packages = PACKAGES
8} catch (MissingPropertyException e) {
9 packages = ""
10}
11
12def components
13try {
14 components = COMPONENTS
15} catch (MissingPropertyException e) {
16 components = ""
17}
18
chnyda5626fc92017-11-28 17:34:06 +010019def storages
20try {
21 storages = STORAGES.tokenize(',')
22} catch (MissingPropertyException e) {
23 storages = ['local']
24}
Jakub Josefa63f9862018-01-11 17:58:38 +010025timeout(time: 12, unit: 'HOURS') {
26 node() {
27 try{
28 stage("promote") {
Jakub Josefe70fdf02018-02-14 13:29:41 +010029 if(_userCanRunPromote(SOURCE, TARGET)){
30 lock("aptly-api") {
31 for (storage in storages) {
32 if (storage == "local") {
33 storage = ""
34 }
35 aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, components, packages, DIFF_ONLY, '-d --timeout 600', DUMP_PUBLISH.toBoolean(), storage)
Jakub Josefa63f9862018-01-11 17:58:38 +010036 }
chnyda9e82e992017-12-04 15:01:54 +010037 }
Jakub Josefe70fdf02018-02-14 13:29:41 +010038 }else{
39 throw new Exception(String.format("You don't have permissions to make aptly promote from source:%s to target:%s ", SOURCE, TARGET))
chnyda5626fc92017-11-28 17:34:06 +010040 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010041 }
Jakub Josefa63f9862018-01-11 17:58:38 +010042 } catch (Throwable e) {
43 // If there was an error or exception thrown, the build failed
44 currentBuild.result = "FAILURE"
45 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
46 throw e
47 } finally {
48 common.sendNotification(currentBuild.result,"",["slack"])
azvyagintsev1e5a9672018-01-15 16:21:44 +020049 def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
50 currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
Jakub Josefc5a223a2017-03-01 14:40:08 +010051 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010052 }
azvyagintsev1e5a9672018-01-15 16:21:44 +020053}
Jakub Josefe70fdf02018-02-14 13:29:41 +010054
55def _userCanRunPromote(source, target){
56 if(source.contains("stable") || target.contains("stable")){
57 // promote from or to stable is restricted to users in aptly-promote-users LDAP group
58 def jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
59 return jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "aptly-promote-stable-users"])
60 }
61 // other types of promote are allowed to everyone
62 return true;
63}