Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 3 | * Promote MCP |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 4 | * |
| 5 | * Expected parameters: |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 6 | * SOURCE_REVISION |
| 7 | * TARGET_REVISION |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 8 | * RELEASE_APTLY |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 9 | * RELEASE_DEB_MIRRORS |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 10 | * RELEASE_DOCKER |
| 11 | * RELEASE_GIT |
| 12 | * APTLY_URL |
| 13 | * APTLY_STORAGES |
| 14 | * DOCKER_CREDENTIALS |
| 15 | * DOCKER_URL |
| 16 | * DOCKER_IMAGES |
| 17 | * GIT_CREDENTIALS |
| 18 | * GIT_REPO_LIST |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 19 | * VCP_IMAGE_LIST - list of images |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 20 | * SYNC_VCP_IMAGE_TO_S3 - boolean |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 21 | * RELEASE_VCP_IMAGES - boolean |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 22 | * EMAIL_NOTIFY |
| 23 | * NOTIFY_RECIPIENTS |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 24 | * |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 25 | */ |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 26 | |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 27 | common = new com.mirantis.mk.Common() |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 28 | |
azvyagintsev | 7977866 | 2018-11-23 18:07:16 +0200 | [diff] [blame^] | 29 | syncVcpImagesToS3 = env.SYNC_VCP_IMAGE_TO_S3 ?: false |
| 30 | emailNotify = env.EMAIL_NOTIFY ?: false |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 31 | |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 32 | def triggerAptlyPromoteJob(aptlyUrl, components, diffOnly, dumpPublish, packages, recreate, source, storages, target) { |
| 33 | build job: "aptly-promote-all-testing-stable", parameters: [ |
| 34 | [$class: 'StringParameterValue', name: 'APTLY_URL', value: aptlyUrl], |
| 35 | [$class: 'StringParameterValue', name: 'COMPONENTS', value: components], |
| 36 | [$class: 'BooleanParameterValue', name: 'DIFF_ONLY', value: diffOnly], |
| 37 | [$class: 'BooleanParameterValue', name: 'DUMP_PUBLISH', value: dumpPublish], |
| 38 | [$class: 'StringParameterValue', name: 'PACKAGES', value: packages], |
| 39 | [$class: 'BooleanParameterValue', name: 'RECREATE', value: recreate], |
| 40 | [$class: 'StringParameterValue', name: 'SOURCE', value: source], |
| 41 | [$class: 'StringParameterValue', name: 'STORAGES', value: storages], |
| 42 | [$class: 'StringParameterValue', name: 'TARGET', value: target], |
| 43 | ] |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 44 | } |
| 45 | |
azvyagintsev | d162b91 | 2018-07-26 10:52:14 +0200 | [diff] [blame] | 46 | def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, targetTag, imageList, sourceImageTag) { |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 47 | build job: "docker-images-mirror", parameters: [ |
| 48 | [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials], |
| 49 | [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl], |
| 50 | [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: targetTag], |
azvyagintsev | f7c65fa | 2018-10-02 14:59:09 +0300 | [diff] [blame] | 51 | [$class: 'TextParameterValue', name: 'IMAGE_LIST', value: imageList], |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 52 | [$class: 'StringParameterValue', name: 'SOURCE_IMAGE_TAG', value: sourceImageTag], |
| 53 | ] |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 56 | def triggerMirrorRepoJob(snapshotId, snapshotName) { |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 57 | build job: "mirror-snapshot-name-all", parameters: [ |
| 58 | [$class: 'StringParameterValue', name: 'SNAPSHOT_NAME', value: snapshotName], |
| 59 | [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: snapshotId], |
| 60 | ] |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Alexander Evseev | e704ca9 | 2018-09-11 11:30:55 +0200 | [diff] [blame] | 63 | def triggerEbfRepoJob(snapshotId, snapshotName) { |
| 64 | build job: "ebf-snapshot-name-all", parameters: [ |
| 65 | [$class: 'StringParameterValue', name: 'SNAPSHOT_NAME', value: snapshotName], |
| 66 | [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: snapshotId], |
| 67 | ] |
| 68 | } |
| 69 | |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 70 | def triggerGitTagJob(gitRepoList, gitCredentials, tag, sourceTag) { |
Alexander Evseev | 8564937 | 2018-10-08 18:06:49 +0200 | [diff] [blame] | 71 | // There is no `nightly` and `testing` build-IDs` in release process |
| 72 | // for git repos |
| 73 | if ( sourceTag in ['nightly', 'testing'] ) sourceTag = 'master' |
azvyagintsev | 21308d0 | 2018-08-30 17:49:33 +0300 | [diff] [blame] | 74 | build job: "tag-git-repos-all", parameters: [ |
azvyagintsev | f7c65fa | 2018-10-02 14:59:09 +0300 | [diff] [blame] | 75 | [$class: 'TextParameterValue', name: 'GIT_REPO_LIST', value: gitRepoList], |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 76 | [$class: 'StringParameterValue', name: 'GIT_CREDENTIALS', value: gitCredentials], |
| 77 | [$class: 'StringParameterValue', name: 'TAG', value: tag], |
| 78 | [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag], |
| 79 | ] |
| 80 | } |
| 81 | |
| 82 | def triggerPromoteVCPJob(VcpImageList, tag, sourceTag) { |
| 83 | build job: "promote-vcp-images-all", parameters: [ |
azvyagintsev | f7c65fa | 2018-10-02 14:59:09 +0300 | [diff] [blame] | 84 | [$class: 'TextParameterValue', name: 'VCP_IMAGE_LIST', value: VcpImageList], |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 85 | [$class: 'StringParameterValue', name: 'TAG', value: tag], |
azvyagintsev | ff65d40 | 2018-10-02 18:37:42 +0300 | [diff] [blame] | 86 | [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag], |
| 87 | [$class: 'BooleanParameterValue', name: 'FORCE_OVERWRITE', value: true], |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 88 | ] |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 89 | } |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 90 | |
azvyagintsev | 7977866 | 2018-11-23 18:07:16 +0200 | [diff] [blame^] | 91 | def triggerSyncVCPJob(VcpImageList, targetTag) { |
| 92 | // Operation must be synced with triggerPromoteVCPJob procedure! |
| 93 | def images = VcpImageList.trim().tokenize() |
| 94 | TargetVcpImageList = '' |
| 95 | for (image in images) { |
| 96 | if (image.startsWith('#')) { |
| 97 | common.warningMsg("Skipping image ${image}") |
| 98 | continue |
| 99 | } |
| 100 | common.infoMsg("Replacing SUBS_SOURCE_VCP_IMAGE_TAG => ${targetTag}") |
| 101 | TargetVcpImageList += image.replace('SUBS_SOURCE_VCP_IMAGE_TAG', targetTag) + '\n' |
| 102 | } |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 103 | build job: "upload-to-s3", parameters: [ |
| 104 | [$class: 'TextParameterValue', name: 'FILENAMES', |
azvyagintsev | 7977866 | 2018-11-23 18:07:16 +0200 | [diff] [blame^] | 105 | value: TargetVcpImageList + TargetVcpImageList.collect({it + '.md5'})] |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 106 | ] |
| 107 | } |
| 108 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 109 | timeout(time: 12, unit: 'HOURS') { |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 110 | node() { |
| 111 | try { |
| 112 | stage("Promote") { |
| 113 | if (RELEASE_APTLY.toBoolean()) { |
| 114 | common.infoMsg("Promoting Aptly") |
| 115 | triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, "(.*)/${SOURCE_REVISION}", APTLY_STORAGES, "{0}/${TARGET_REVISION}") |
| 116 | } |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 117 | |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 118 | if (RELEASE_DEB_MIRRORS.toBoolean()) { |
| 119 | common.infoMsg("Promoting Debmirrors") |
| 120 | triggerMirrorRepoJob(SOURCE_REVISION, TARGET_REVISION) |
| 121 | } |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 122 | |
Alexander Evseev | e704ca9 | 2018-09-11 11:30:55 +0200 | [diff] [blame] | 123 | if (RELEASE_EBF_MIRRORS.toBoolean()) { |
| 124 | common.infoMsg("Promoting Emergency Bug Fix Debmirrors") |
| 125 | triggerEbfRepoJob(SOURCE_REVISION, TARGET_REVISION) |
| 126 | } |
| 127 | |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 128 | if (RELEASE_DOCKER.toBoolean()) { |
| 129 | common.infoMsg("Promoting Docker images") |
| 130 | triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, TARGET_REVISION, DOCKER_IMAGES, SOURCE_REVISION) |
| 131 | } |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 132 | |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 133 | if (RELEASE_GIT.toBoolean()) { |
| 134 | common.infoMsg("Promoting Git repositories") |
| 135 | triggerGitTagJob(GIT_REPO_LIST, GIT_CREDENTIALS, TARGET_REVISION, SOURCE_REVISION) |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 136 | |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 137 | } |
| 138 | if (RELEASE_VCP_IMAGES.toBoolean()) { |
| 139 | common.infoMsg("Promoting VCP images") |
| 140 | triggerPromoteVCPJob(VCP_IMAGE_LIST, TARGET_REVISION, SOURCE_REVISION) |
| 141 | |
| 142 | } |
azvyagintsev | 7977866 | 2018-11-23 18:07:16 +0200 | [diff] [blame^] | 143 | if (syncVcpImagesToS3.toBoolean()) { |
Alexander Evseev | 1edde6b | 2018-10-30 15:22:44 +0300 | [diff] [blame] | 144 | common.infoMsg("Syncing VCP images from internal: http://images.mcp.mirantis.net/ to s3: images.mirantis.com") |
azvyagintsev | 7977866 | 2018-11-23 18:07:16 +0200 | [diff] [blame^] | 145 | triggerSyncVCPJob(VCP_IMAGE_LIST, TARGET_REVISION) |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 146 | } |
| 147 | if (emailNotify) { |
| 148 | notify_text = "MCP Promotion ${env.SOURCE_REVISION} => ${env.TARGET_REVISION} has been done" |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 149 | emailext(to: NOTIFY_RECIPIENTS, |
azvyagintsev | 759734c | 2018-10-03 13:57:54 +0300 | [diff] [blame] | 150 | body: notify_text, |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 151 | subject: "MCP Promotion has been done") |
| 152 | } |
| 153 | } |
| 154 | } catch (Throwable e) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 155 | // If there was an error or exception thrown, the build failed |
| 156 | currentBuild.result = "FAILURE" |
| 157 | throw e |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 158 | } |
azvyagintsev | 8778188 | 2018-08-30 18:45:22 +0300 | [diff] [blame] | 159 | } |
| 160 | } |