blob: 0f51a90ab193dd80e11d534f9d0eb6da06b685a2 [file] [log] [blame]
Jakub Josefc5a223a2017-03-01 14:40:08 +01001def common = new com.mirantis.mk.Common()
2def aptly = new com.mirantis.mk.Aptly()
Jakub Josef70fb4bc2018-02-20 16:05:44 +01003def jenkinsUtils = new com.mirantis.mk.JenkinsUtils()
chnyda6a3553e2017-03-21 13:20:15 +01004
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 Josef5a2258a2018-03-13 11:45:35 +010025
26def insufficientPermissions = false
27
Jakub Josefa63f9862018-01-11 17:58:38 +010028timeout(time: 12, unit: 'HOURS') {
29 node() {
Jakub Josef5a2258a2018-03-13 11:45:35 +010030 try {
Jakub Josefa63f9862018-01-11 17:58:38 +010031 stage("promote") {
Jakub Josef70fb4bc2018-02-20 16:05:44 +010032 // promote is restricted to users in aptly-promote-users LDAP group
33 if(jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "aptly-promote-users"])){
Jakub Josefe70fdf02018-02-14 13:29:41 +010034 lock("aptly-api") {
35 for (storage in storages) {
36 if (storage == "local") {
37 storage = ""
38 }
39 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 +010040 }
chnyda9e82e992017-12-04 15:01:54 +010041 }
Jakub Josefe70fdf02018-02-14 13:29:41 +010042 }else{
Jakub Josef5a2258a2018-03-13 11:45:35 +010043 insufficientPermissions = true
Jakub Josef70fb4bc2018-02-20 16:05:44 +010044 throw new Exception(String.format("You don't have permissions to make aptly promote from source:%s to target:%s! Only CI/CD and QA team can perform aptly promote.", SOURCE, TARGET))
chnyda5626fc92017-11-28 17:34:06 +010045 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010046 }
Jakub Josefa63f9862018-01-11 17:58:38 +010047 } catch (Throwable e) {
48 // If there was an error or exception thrown, the build failed
Jakub Josef5a2258a2018-03-13 11:45:35 +010049 if (insufficientPermissions) {
50 currentBuild.result = "ABORTED"
51 currentBuild.description = "Promote aborted due to insufficient permissions"
52 } else {
53 currentBuild.result = "FAILURE"
54 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
55 }
Jakub Josefa63f9862018-01-11 17:58:38 +010056 throw e
57 } finally {
Jakub Josef5a2258a2018-03-13 11:45:35 +010058 if (!insufficientPermissions) {
59 common.sendNotification(currentBuild.result,"",["slack"])
60 def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
61 currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
62 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010063 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010064 }
azvyagintsev1e5a9672018-01-15 16:21:44 +020065}
Jakub Josefe70fdf02018-02-14 13:29:41 +010066