blob: c7f41f831cd1a1fb17625671cb0f6e30a7314713 [file] [log] [blame]
Richard Felkl37ee1e32017-12-11 10:01:39 +01001/**
2 *
Richard Felkl56082e92017-12-20 23:39:53 +01003 * Promote MCP
Richard Felkl37ee1e32017-12-11 10:01:39 +01004 *
5 * Expected parameters:
Richard Felkl56082e92017-12-20 23:39:53 +01006 * SOURCE_REVISION
7 * TARGET_REVISION
Richard Felkl37ee1e32017-12-11 10:01:39 +01008 * RELEASE_APTLY
Richard Felkl56082e92017-12-20 23:39:53 +01009 * RELEASE_DEB_MIRRORS
Richard Felkl37ee1e32017-12-11 10:01:39 +010010 * 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
azvyagintsev87781882018-08-30 18:45:22 +030019 * VCP_IMAGE_LIST - list of images
azvyagintsev759734c2018-10-03 13:57:54 +030020 * SYNC_VCP_IMAGE_TO_S3 - boolean
azvyagintsev87781882018-08-30 18:45:22 +030021 * RELEASE_VCP_IMAGES - boolean
Richard Felklc8c5a5a2018-04-19 17:06:30 +020022 * EMAIL_NOTIFY
23 * NOTIFY_RECIPIENTS
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +040024 * PKG_REPO_LIST
azvyagintsev4696d662018-11-23 19:48:09 +020025 *
azvyagintsev87781882018-08-30 18:45:22 +030026 */
Richard Felkl37ee1e32017-12-11 10:01:39 +010027
Richard Felkl55175f52017-12-20 14:53:41 +010028common = new com.mirantis.mk.Common()
azvyagintsev759734c2018-10-03 13:57:54 +030029
azvyagintsev79778662018-11-23 18:07:16 +020030syncVcpImagesToS3 = env.SYNC_VCP_IMAGE_TO_S3 ?: false
31emailNotify = env.EMAIL_NOTIFY ?: false
Richard Felkl37ee1e32017-12-11 10:01:39 +010032
azvyagintsev87781882018-08-30 18:45:22 +030033def triggerAptlyPromoteJob(aptlyUrl, components, diffOnly, dumpPublish, packages, recreate, source, storages, target) {
34 build job: "aptly-promote-all-testing-stable", parameters: [
35 [$class: 'StringParameterValue', name: 'APTLY_URL', value: aptlyUrl],
36 [$class: 'StringParameterValue', name: 'COMPONENTS', value: components],
37 [$class: 'BooleanParameterValue', name: 'DIFF_ONLY', value: diffOnly],
38 [$class: 'BooleanParameterValue', name: 'DUMP_PUBLISH', value: dumpPublish],
39 [$class: 'StringParameterValue', name: 'PACKAGES', value: packages],
40 [$class: 'BooleanParameterValue', name: 'RECREATE', value: recreate],
41 [$class: 'StringParameterValue', name: 'SOURCE', value: source],
42 [$class: 'StringParameterValue', name: 'STORAGES', value: storages],
43 [$class: 'StringParameterValue', name: 'TARGET', value: target],
44 ]
Richard Felkl37ee1e32017-12-11 10:01:39 +010045}
46
azvyagintsevd162b912018-07-26 10:52:14 +020047def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, targetTag, imageList, sourceImageTag) {
azvyagintsev87781882018-08-30 18:45:22 +030048 build job: "docker-images-mirror", parameters: [
49 [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials],
50 [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl],
51 [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: targetTag],
azvyagintsevf7c65fa2018-10-02 14:59:09 +030052 [$class: 'TextParameterValue', name: 'IMAGE_LIST', value: imageList],
azvyagintsev87781882018-08-30 18:45:22 +030053 [$class: 'StringParameterValue', name: 'SOURCE_IMAGE_TAG', value: sourceImageTag],
54 ]
Richard Felkl37ee1e32017-12-11 10:01:39 +010055}
56
Richard Felkl56082e92017-12-20 23:39:53 +010057def triggerMirrorRepoJob(snapshotId, snapshotName) {
azvyagintsev87781882018-08-30 18:45:22 +030058 build job: "mirror-snapshot-name-all", parameters: [
59 [$class: 'StringParameterValue', name: 'SNAPSHOT_NAME', value: snapshotName],
60 [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: snapshotId],
61 ]
Richard Felkl56082e92017-12-20 23:39:53 +010062}
63
Alexander Evseeve704ca92018-09-11 11:30:55 +020064def triggerEbfRepoJob(snapshotId, snapshotName) {
65 build job: "ebf-snapshot-name-all", parameters: [
66 [$class: 'StringParameterValue', name: 'SNAPSHOT_NAME', value: snapshotName],
67 [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: snapshotId],
68 ]
69}
70
azvyagintsev3280a0c2018-07-31 08:44:43 +020071def triggerGitTagJob(gitRepoList, gitCredentials, tag, sourceTag) {
Alexander Evseev85649372018-10-08 18:06:49 +020072 // There is no `nightly` and `testing` build-IDs` in release process
73 // for git repos
azvyagintsev58301222019-01-08 13:34:35 +020074 if (sourceTag in ['nightly', 'testing']) {
75 sourceTag = 'master'
76 }
azvyagintsev21308d02018-08-30 17:49:33 +030077 build job: "tag-git-repos-all", parameters: [
azvyagintsevf7c65fa2018-10-02 14:59:09 +030078 [$class: 'TextParameterValue', name: 'GIT_REPO_LIST', value: gitRepoList],
azvyagintsev87781882018-08-30 18:45:22 +030079 [$class: 'StringParameterValue', name: 'GIT_CREDENTIALS', value: gitCredentials],
80 [$class: 'StringParameterValue', name: 'TAG', value: tag],
81 [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag],
82 ]
83}
84
85def triggerPromoteVCPJob(VcpImageList, tag, sourceTag) {
86 build job: "promote-vcp-images-all", parameters: [
azvyagintsevf7c65fa2018-10-02 14:59:09 +030087 [$class: 'TextParameterValue', name: 'VCP_IMAGE_LIST', value: VcpImageList],
azvyagintsev87781882018-08-30 18:45:22 +030088 [$class: 'StringParameterValue', name: 'TAG', value: tag],
azvyagintsevff65d402018-10-02 18:37:42 +030089 [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag],
90 [$class: 'BooleanParameterValue', name: 'FORCE_OVERWRITE', value: true],
azvyagintsev87781882018-08-30 18:45:22 +030091 ]
Richard Felkl37ee1e32017-12-11 10:01:39 +010092}
Richard Felklc8c5a5a2018-04-19 17:06:30 +020093
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +040094def triggerPkgPromoteJob(PkgRepoList, PromoteFrom, PromoteTo) {
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +040095 //For repositories with per-package promote such as extra, ceph
96 //we use different approaches for different steps of promoting
Sergey Otpuschennikov9b532cd2019-02-06 17:03:33 +040097 def repos = PkgRepoList.trim().tokenize("\n")
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +040098 def RepoName, RepoDist, PackagesToPromote
99 for (repo in repos) {
azvyagintsev58301222019-01-08 13:34:35 +0200100 if (repo.startsWith('#')) {
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400101 common.warningMsg("Skipping repo ${repo}")
102 continue
103 }
azvyagintsev58301222019-01-08 13:34:35 +0200104 if (repo.trim().indexOf(' ') == -1) {
105 throw new IllegalArgumentException("Wrong format of repository and commit input")
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400106 }
107 repoArray = repo.trim().tokenize(' ')
108 RepoName = repoArray[0]
109 RepoDist = repoArray[1]
110 PackagesToPromote = repoArray[2]
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +0400111 //During promote from testing to proposed we use per-package promote
112 if (SOURCE_REVISION == 'testing') {
113 build job: "pkg-promote", parameters: [
Sergey Otpuschennikov9b532cd2019-02-06 17:03:33 +0400114 [$class: 'StringParameterValue', name: 'repoName', value: RepoName],
115 [$class: 'StringParameterValue', name: 'repoDist', value: RepoDist],
116 [$class: 'StringParameterValue', name: 'promoteFrom', value: PromoteFrom],
117 [$class: 'StringParameterValue', name: 'promoteTo', value: PromoteTo],
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +0400118 [$class: 'TextParameterValue', name: 'packagesToPromote', value: PackagesToPromote],
119 ]
120 //In promote from proposed to release we move links to snapshots
121 } else if (SOURCE_REVISION == 'proposed') {
122 build job: "mirror-snapshot-pkg-name-${RepoName}-${RepoDist}", parameters: [
Sergey Otpuschennikov37ad0bc2019-02-06 17:30:36 +0400123 [$class: 'StringParameterValue', name: 'MCP_VERSION', value: PromoteTo],
124 [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: PromoteFrom],
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +0400125 ]
126 }
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400127 }
128}
129
azvyagintsev79778662018-11-23 18:07:16 +0200130def triggerSyncVCPJob(VcpImageList, targetTag) {
131 // Operation must be synced with triggerPromoteVCPJob procedure!
132 def images = VcpImageList.trim().tokenize()
133 TargetVcpImageList = ''
134 for (image in images) {
135 if (image.startsWith('#')) {
136 common.warningMsg("Skipping image ${image}")
137 continue
138 }
139 common.infoMsg("Replacing SUBS_SOURCE_VCP_IMAGE_TAG => ${targetTag}")
azvyagintsev4696d662018-11-23 19:48:09 +0200140 TargetVcpImageList += image.replace('SUBS_SOURCE_VCP_IMAGE_TAG', targetTag) + '\n' +
141 image.replace('SUBS_SOURCE_VCP_IMAGE_TAG', targetTag).trim() + '.md5' + '\n'
142
azvyagintsev79778662018-11-23 18:07:16 +0200143 }
Kirill Mashchenkoe866b302018-11-23 21:08:15 +0400144 build job: "upload_images_to_s3", parameters: [
azvyagintsev4696d662018-11-23 19:48:09 +0200145 [$class: 'TextParameterValue', name: 'FILENAMES',
146 value : TargetVcpImageList]
azvyagintsev759734c2018-10-03 13:57:54 +0300147 ]
148}
149
Jakub Josefa63f9862018-01-11 17:58:38 +0100150timeout(time: 12, unit: 'HOURS') {
azvyagintsev87781882018-08-30 18:45:22 +0300151 node() {
152 try {
153 stage("Promote") {
154 if (RELEASE_APTLY.toBoolean()) {
155 common.infoMsg("Promoting Aptly")
156 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, "(.*)/${SOURCE_REVISION}", APTLY_STORAGES, "{0}/${TARGET_REVISION}")
157 }
Richard Felkl56082e92017-12-20 23:39:53 +0100158
Sergey Otpuschennikov6f4d6852018-12-27 19:27:58 +0400159 if (PKG_PROMOTE.toBoolean()) {
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400160 common.infoMsg("Promoting Extra and Ceph packages")
161 triggerPkgPromoteJob(PKG_REPO_LIST, SOURCE_REVISION, TARGET_REVISION)
162 }
163
azvyagintsev87781882018-08-30 18:45:22 +0300164 if (RELEASE_DEB_MIRRORS.toBoolean()) {
165 common.infoMsg("Promoting Debmirrors")
166 triggerMirrorRepoJob(SOURCE_REVISION, TARGET_REVISION)
167 }
Richard Felkl56082e92017-12-20 23:39:53 +0100168
Alexander Evseeve704ca92018-09-11 11:30:55 +0200169 if (RELEASE_EBF_MIRRORS.toBoolean()) {
170 common.infoMsg("Promoting Emergency Bug Fix Debmirrors")
171 triggerEbfRepoJob(SOURCE_REVISION, TARGET_REVISION)
172 }
173
azvyagintsev87781882018-08-30 18:45:22 +0300174 if (RELEASE_DOCKER.toBoolean()) {
175 common.infoMsg("Promoting Docker images")
176 triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, TARGET_REVISION, DOCKER_IMAGES, SOURCE_REVISION)
177 }
Richard Felkl56082e92017-12-20 23:39:53 +0100178
azvyagintsev87781882018-08-30 18:45:22 +0300179 if (RELEASE_GIT.toBoolean()) {
180 common.infoMsg("Promoting Git repositories")
181 triggerGitTagJob(GIT_REPO_LIST, GIT_CREDENTIALS, TARGET_REVISION, SOURCE_REVISION)
Richard Felklc8c5a5a2018-04-19 17:06:30 +0200182
azvyagintsev87781882018-08-30 18:45:22 +0300183 }
184 if (RELEASE_VCP_IMAGES.toBoolean()) {
185 common.infoMsg("Promoting VCP images")
186 triggerPromoteVCPJob(VCP_IMAGE_LIST, TARGET_REVISION, SOURCE_REVISION)
187
188 }
azvyagintsev79778662018-11-23 18:07:16 +0200189 if (syncVcpImagesToS3.toBoolean()) {
Alexander Evseev1edde6b2018-10-30 15:22:44 +0300190 common.infoMsg("Syncing VCP images from internal: http://images.mcp.mirantis.net/ to s3: images.mirantis.com")
azvyagintsev79778662018-11-23 18:07:16 +0200191 triggerSyncVCPJob(VCP_IMAGE_LIST, TARGET_REVISION)
azvyagintsev759734c2018-10-03 13:57:54 +0300192 }
193 if (emailNotify) {
194 notify_text = "MCP Promotion ${env.SOURCE_REVISION} => ${env.TARGET_REVISION} has been done"
azvyagintsev87781882018-08-30 18:45:22 +0300195 emailext(to: NOTIFY_RECIPIENTS,
azvyagintsev759734c2018-10-03 13:57:54 +0300196 body: notify_text,
azvyagintsev87781882018-08-30 18:45:22 +0300197 subject: "MCP Promotion has been done")
198 }
199 }
200 } catch (Throwable e) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100201 // If there was an error or exception thrown, the build failed
202 currentBuild.result = "FAILURE"
203 throw e
Richard Felkl37ee1e32017-12-11 10:01:39 +0100204 }
azvyagintsev87781882018-08-30 18:45:22 +0300205 }
206}