blob: 7c7f492da755d1e30dbba8c3ced8671711481b97 [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 {
31 stage("promote") {
32 // promote is restricted to users in aptly-promote-users LDAP group
Romanff4e4832018-12-28 13:28:42 +030033 if(jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "release-engineering", "opencontrail-all"])){
Roman1675fc22018-12-28 12:56:48 +030034 lock("aptly-api") {
35 for (storage in storages) {
36 if (storage == "local") {
37 storage = ""
38 }
39 retry(2) {
40 aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, components, packages, DIFF_ONLY, '-d --timeout 600', DUMP_PUBLISH.toBoolean(), storage)
41 }
42 }
43 }
44 }else{
45 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))
Kirill Mashchenko91abe132018-12-04 12:51:55 +040046 }
Jakub Josefa63f9862018-01-11 17:58:38 +010047 }
Kirill Mashchenko91abe132018-12-04 12:51:55 +040048 } catch (Throwable e) {
49 // If there was an error or exception thrown, the build failed
50 if (insufficientPermissions) {
51 currentBuild.result = "ABORTED"
52 currentBuild.description = "Promote aborted due to insufficient permissions"
53 } else {
54 currentBuild.result = "FAILURE"
55 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
56 }
57 throw e
58 } finally {
59 if (!insufficientPermissions) {
60 common.sendNotification(currentBuild.result, "", ["slack"])
61 def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}"
62 currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr
63 }
chnyda5626fc92017-11-28 17:34:06 +010064 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010065 }
azvyagintsev1e5a9672018-01-15 16:21:44 +020066}