Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def aptly = new com.mirantis.mk.Aptly() |
Jakub Josef | 70fb4bc | 2018-02-20 16:05:44 +0100 | [diff] [blame] | 3 | def jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
chnyda | 6a3553e | 2017-03-21 13:20:15 +0100 | [diff] [blame] | 4 | |
| 5 | def packages |
| 6 | try { |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 7 | packages = PACKAGES |
chnyda | 6a3553e | 2017-03-21 13:20:15 +0100 | [diff] [blame] | 8 | } catch (MissingPropertyException e) { |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 9 | packages = "" |
chnyda | 6a3553e | 2017-03-21 13:20:15 +0100 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | def components |
| 13 | try { |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 14 | components = COMPONENTS |
chnyda | 6a3553e | 2017-03-21 13:20:15 +0100 | [diff] [blame] | 15 | } catch (MissingPropertyException e) { |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 16 | components = "" |
chnyda | 6a3553e | 2017-03-21 13:20:15 +0100 | [diff] [blame] | 17 | } |
| 18 | |
chnyda | 5626fc9 | 2017-11-28 17:34:06 +0100 | [diff] [blame] | 19 | def storages |
| 20 | try { |
| 21 | storages = STORAGES.tokenize(',') |
| 22 | } catch (MissingPropertyException e) { |
| 23 | storages = ['local'] |
| 24 | } |
Jakub Josef | 5a2258a | 2018-03-13 11:45:35 +0100 | [diff] [blame] | 25 | |
| 26 | def insufficientPermissions = false |
| 27 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 28 | timeout(time: 12, unit: 'HOURS') { |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 29 | node("docker&&hardware") { |
| 30 | try { |
Kirill Mashchenko | 0dc61e4 | 2019-01-11 03:53:56 +0400 | [diff] [blame] | 31 | if ("testing" in TARGET && !jenkinsUtils.currentUserInGroup(["release-engineering", "aptly-promote-users"])) { |
| 32 | insufficientPermissions = true |
| 33 | throw new Exception("Only release-engineering or aptly-promote-users can perform promote to testing.") |
| 34 | } else if (!jenkinsUtils.currentUserInGroup(["release-engineering"])) { |
| 35 | insufficientPermissions = true |
| 36 | throw new Exception("Only release-engineering team can perform promote.") |
| 37 | } |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 38 | stage("promote") { |
| 39 | // promote is restricted to users in aptly-promote-users LDAP group |
Roman | ff4e483 | 2018-12-28 13:28:42 +0300 | [diff] [blame] | 40 | if(jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "release-engineering", "opencontrail-all"])){ |
Roman | 1675fc2 | 2018-12-28 12:56:48 +0300 | [diff] [blame] | 41 | 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) |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | }else{ |
| 52 | 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 Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 53 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 54 | } |
Kirill Mashchenko | 91abe13 | 2018-12-04 12:51:55 +0400 | [diff] [blame] | 55 | } catch (Throwable e) { |
| 56 | // If there was an error or exception thrown, the build failed |
| 57 | if (insufficientPermissions) { |
| 58 | currentBuild.result = "ABORTED" |
| 59 | currentBuild.description = "Promote aborted due to insufficient permissions" |
| 60 | } else { |
| 61 | currentBuild.result = "FAILURE" |
| 62 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 63 | } |
| 64 | throw e |
| 65 | } finally { |
| 66 | if (!insufficientPermissions) { |
| 67 | common.sendNotification(currentBuild.result, "", ["slack"]) |
| 68 | def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}" |
| 69 | currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr |
| 70 | } |
chnyda | 5626fc9 | 2017-11-28 17:34:06 +0100 | [diff] [blame] | 71 | } |
Jakub Josef | c5a223a | 2017-03-01 14:40:08 +0100 | [diff] [blame] | 72 | } |
azvyagintsev | 1e5a967 | 2018-01-15 16:21:44 +0200 | [diff] [blame] | 73 | } |