| def common = new com.mirantis.mk.Common() |
| def aptly = new com.mirantis.mk.Aptly() |
| |
| |
| def packages |
| try { |
| packages = PACKAGES |
| } catch (MissingPropertyException e) { |
| packages = "" |
| } |
| |
| def components |
| try { |
| components = COMPONENTS |
| } catch (MissingPropertyException e) { |
| components = "" |
| } |
| |
| def storages |
| try { |
| storages = STORAGES.tokenize(',') |
| } catch (MissingPropertyException e) { |
| storages = ['local'] |
| } |
| timeout(time: 12, unit: 'HOURS') { |
| node() { |
| try{ |
| stage("promote") { |
| if(_userCanRunPromote(SOURCE, TARGET)){ |
| lock("aptly-api") { |
| for (storage in storages) { |
| if (storage == "local") { |
| storage = "" |
| } |
| aptly.promotePublish(APTLY_URL, SOURCE, TARGET, RECREATE, components, packages, DIFF_ONLY, '-d --timeout 600', DUMP_PUBLISH.toBoolean(), storage) |
| } |
| } |
| }else{ |
| throw new Exception(String.format("You don't have permissions to make aptly promote from source:%s to target:%s ", SOURCE, TARGET)) |
| } |
| } |
| } catch (Throwable e) { |
| // If there was an error or exception thrown, the build failed |
| currentBuild.result = "FAILURE" |
| currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| throw e |
| } finally { |
| common.sendNotification(currentBuild.result,"",["slack"]) |
| def _extra_descr = "${SOURCE}=>${TARGET}:\n${COMPONENTS} ${packages}" |
| currentBuild.description = currentBuild.description ? _extra_descr + " " + currentBuild.description : _extra_descr |
| } |
| } |
| } |
| |
| def _userCanRunPromote(source, target){ |
| if(source.contains("stable") || target.contains("stable")){ |
| // promote from or to stable is restricted to users in aptly-promote-users LDAP group |
| def jenkinsUtils = new com.mirantis.mk.JenkinsUtils() |
| return jenkinsUtils.currentUserInGroups(["mcp-cicd-admins", "aptly-promote-stable-users"]) |
| } |
| // other types of promote are allowed to everyone |
| return true; |
| } |