blob: b9545a7d16f401569678993a06d624efa2d2b9d8 [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 {
Kirill Mashchenko91abe132018-12-04 12:51:55 +04007 packages = PACKAGES
chnyda6a3553e2017-03-21 13:20:15 +01008} catch (MissingPropertyException e) {
Kirill Mashchenko91abe132018-12-04 12:51:55 +04009 packages = ""
chnyda6a3553e2017-03-21 13:20:15 +010010}
11
12def components
13try {
Kirill Mashchenko91abe132018-12-04 12:51:55 +040014 components = COMPONENTS
chnyda6a3553e2017-03-21 13:20:15 +010015} catch (MissingPropertyException e) {
Kirill Mashchenko91abe132018-12-04 12:51:55 +040016 components = ""
chnyda6a3553e2017-03-21 13:20:15 +010017}
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') {
Kirill Mashchenko91abe132018-12-04 12:51:55 +040029 node("docker&&hardware") {
30 try {
Kirill Mashchenko29fe8fd2018-12-12 14:48:22 +040031
Kyrylo Mashchenko2d92eaa2018-12-12 11:36:39 +000032 if (("testing" in TARGET || "proposed" in TARGET) && !jenkinsUtils.currentUserInGroup(["release-engineering", "aptly-promote-users"])) {
Kirill Mashchenko824fd552018-12-05 12:58:40 +040033 insufficientPermissions = true
Kyrylo Mashchenko2d92eaa2018-12-12 11:36:39 +000034 throw new Exception("Only release-engineering or aptly-promote-users can perform promote to testing.")
35 } else if (!jenkinsUtils.currentUserInGroup(["release-engineering"])) {
36 insufficientPermissions = true
37 throw new Exception("Only release-engineering team can perform promote.")
Kirill Mashchenko824fd552018-12-05 12:58:40 +040038 }
Kirill Mashchenko91abe132018-12-04 12:51:55 +040039 stage("promote") {
40 // promote is restricted to users in aptly-promote-users LDAP group
Kirill Mashchenko824fd552018-12-05 12:58:40 +040041 lock("aptly-api") {
42 for (storage in storages) {
43 if (storage == "local") {
44 storage = ""
45 }
46 retry(2) {
47 aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, components, packages, DIFF_ONLY, '-d --timeout 600', DUMP_PUBLISH.toBoolean(), storage)
Kirill Mashchenko91abe132018-12-04 12:51:55 +040048 }
49 }
Kirill Mashchenko91abe132018-12-04 12:51:55 +040050 }
Jakub Josefa63f9862018-01-11 17:58:38 +010051 }
Kirill Mashchenko91abe132018-12-04 12:51:55 +040052 } catch (Throwable e) {
53 // If there was an error or exception thrown, the build failed
54 if (insufficientPermissions) {
55 currentBuild.result = "ABORTED"
56 currentBuild.description = "Promote aborted due to insufficient permissions"
57 } else {
58 currentBuild.result = "FAILURE"
59 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
60 }
61 throw e
62 } finally {
63 if (!insufficientPermissions) {
64 common.sendNotification(currentBuild.result, "", ["slack"])
65 def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
66 currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
67 }
chnyda5626fc92017-11-28 17:34:06 +010068 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010069 }
azvyagintsev1e5a9672018-01-15 16:21:44 +020070}
Jakub Josefe70fdf02018-02-14 13:29:41 +010071