blob: 27290e9e3ab44eba27f1fc6b60cf117d82cc8bac [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
azvyagintsev4696d662018-11-23 19:48:09 +020024 *
azvyagintsev87781882018-08-30 18:45:22 +030025 */
Richard Felkl37ee1e32017-12-11 10:01:39 +010026
Richard Felkl55175f52017-12-20 14:53:41 +010027common = new com.mirantis.mk.Common()
azvyagintsev759734c2018-10-03 13:57:54 +030028
azvyagintsev79778662018-11-23 18:07:16 +020029syncVcpImagesToS3 = env.SYNC_VCP_IMAGE_TO_S3 ?: false
30emailNotify = env.EMAIL_NOTIFY ?: false
Richard Felkl37ee1e32017-12-11 10:01:39 +010031
azvyagintsev87781882018-08-30 18:45:22 +030032def 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 Felkl37ee1e32017-12-11 10:01:39 +010044}
45
azvyagintsevd162b912018-07-26 10:52:14 +020046def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, targetTag, imageList, sourceImageTag) {
azvyagintsev87781882018-08-30 18:45:22 +030047 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],
azvyagintsevf7c65fa2018-10-02 14:59:09 +030051 [$class: 'TextParameterValue', name: 'IMAGE_LIST', value: imageList],
azvyagintsev87781882018-08-30 18:45:22 +030052 [$class: 'StringParameterValue', name: 'SOURCE_IMAGE_TAG', value: sourceImageTag],
53 ]
Richard Felkl37ee1e32017-12-11 10:01:39 +010054}
55
Richard Felkl56082e92017-12-20 23:39:53 +010056def triggerMirrorRepoJob(snapshotId, snapshotName) {
azvyagintsev87781882018-08-30 18:45:22 +030057 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 Felkl56082e92017-12-20 23:39:53 +010061}
62
Alexander Evseeve704ca92018-09-11 11:30:55 +020063def 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
azvyagintsev3280a0c2018-07-31 08:44:43 +020070def triggerGitTagJob(gitRepoList, gitCredentials, tag, sourceTag) {
Alexander Evseev85649372018-10-08 18:06:49 +020071 // There is no `nightly` and `testing` build-IDs` in release process
72 // for git repos
azvyagintsev234c8c12019-01-08 13:34:35 +020073 if (sourceTag in ['nightly', 'testing']) {
74 sourceTag = 'master'
75 }
azvyagintsev21308d02018-08-30 17:49:33 +030076 build job: "tag-git-repos-all", parameters: [
azvyagintsevf7c65fa2018-10-02 14:59:09 +030077 [$class: 'TextParameterValue', name: 'GIT_REPO_LIST', value: gitRepoList],
azvyagintsev87781882018-08-30 18:45:22 +030078 [$class: 'StringParameterValue', name: 'GIT_CREDENTIALS', value: gitCredentials],
79 [$class: 'StringParameterValue', name: 'TAG', value: tag],
80 [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag],
81 ]
82}
83
84def triggerPromoteVCPJob(VcpImageList, tag, sourceTag) {
85 build job: "promote-vcp-images-all", parameters: [
azvyagintsevf7c65fa2018-10-02 14:59:09 +030086 [$class: 'TextParameterValue', name: 'VCP_IMAGE_LIST', value: VcpImageList],
azvyagintsev87781882018-08-30 18:45:22 +030087 [$class: 'StringParameterValue', name: 'TAG', value: tag],
azvyagintsevff65d402018-10-02 18:37:42 +030088 [$class: 'StringParameterValue', name: 'SOURCE_TAG', value: sourceTag],
89 [$class: 'BooleanParameterValue', name: 'FORCE_OVERWRITE', value: true],
azvyagintsev87781882018-08-30 18:45:22 +030090 ]
Richard Felkl37ee1e32017-12-11 10:01:39 +010091}
Richard Felklc8c5a5a2018-04-19 17:06:30 +020092
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +040093def triggerPkgPromoteJob(PkgRepoList, PromoteFrom, PromoteTo) {
94 def repos = PkgRepoList.trim().tokenize()
95 def RepoName, RepoDist, PackagesToPromote
96 for (repo in repos) {
azvyagintsev234c8c12019-01-08 13:34:35 +020097 if (repo.startsWith('#')) {
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +040098 common.warningMsg("Skipping repo ${repo}")
99 continue
100 }
azvyagintsev234c8c12019-01-08 13:34:35 +0200101 if (repo.trim().indexOf(' ') == -1) {
102 throw new IllegalArgumentException("Wrong format of repository and commit input")
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400103 }
104 repoArray = repo.trim().tokenize(' ')
105 RepoName = repoArray[0]
106 RepoDist = repoArray[1]
107 PackagesToPromote = repoArray[2]
108 build job: "pkg-promote", parameters: [
109 [$class: 'ChoiceParameterValue', name: 'repoName', value: RepoName],
110 [$class: 'ChoiceParameterValue', name: 'repoDist', value: RepoDist],
111 [$class: 'ChoiceParameterValue', name: 'promoteFrom', value: PromoteFrom],
112 [$class: 'ChoiceParameterValue', name: 'promoteTo', value: PromoteTo],
113 [$class: 'TextParameterValue', name: 'packagesToPromote', value: PackagesToPromote],
114 ]
115 }
116}
117
azvyagintsev79778662018-11-23 18:07:16 +0200118def triggerSyncVCPJob(VcpImageList, targetTag) {
119 // Operation must be synced with triggerPromoteVCPJob procedure!
120 def images = VcpImageList.trim().tokenize()
121 TargetVcpImageList = ''
122 for (image in images) {
123 if (image.startsWith('#')) {
124 common.warningMsg("Skipping image ${image}")
125 continue
126 }
127 common.infoMsg("Replacing SUBS_SOURCE_VCP_IMAGE_TAG => ${targetTag}")
azvyagintsev4696d662018-11-23 19:48:09 +0200128 TargetVcpImageList += image.replace('SUBS_SOURCE_VCP_IMAGE_TAG', targetTag) + '\n' +
129 image.replace('SUBS_SOURCE_VCP_IMAGE_TAG', targetTag).trim() + '.md5' + '\n'
130
azvyagintsev79778662018-11-23 18:07:16 +0200131 }
Kirill Mashchenkoe866b302018-11-23 21:08:15 +0400132 build job: "upload_images_to_s3", parameters: [
azvyagintsev4696d662018-11-23 19:48:09 +0200133 [$class: 'TextParameterValue', name: 'FILENAMES',
134 value : TargetVcpImageList]
azvyagintsev759734c2018-10-03 13:57:54 +0300135 ]
136}
137
Jakub Josefa63f9862018-01-11 17:58:38 +0100138timeout(time: 12, unit: 'HOURS') {
azvyagintsev87781882018-08-30 18:45:22 +0300139 node() {
140 try {
141 stage("Promote") {
142 if (RELEASE_APTLY.toBoolean()) {
143 common.infoMsg("Promoting Aptly")
144 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, "(.*)/${SOURCE_REVISION}", APTLY_STORAGES, "{0}/${TARGET_REVISION}")
145 }
Richard Felkl56082e92017-12-20 23:39:53 +0100146
Sergey Otpuschennikovb0c4db72018-12-19 19:12:54 +0400147 if (PKG_PROMOTE.toBoolean() && SOURCE_REVISION == 'testing') {
148 common.infoMsg("Promoting Extra and Ceph packages")
149 triggerPkgPromoteJob(PKG_REPO_LIST, SOURCE_REVISION, TARGET_REVISION)
150 }
151
azvyagintsev87781882018-08-30 18:45:22 +0300152 if (RELEASE_DEB_MIRRORS.toBoolean()) {
153 common.infoMsg("Promoting Debmirrors")
154 triggerMirrorRepoJob(SOURCE_REVISION, TARGET_REVISION)
155 }
Richard Felkl56082e92017-12-20 23:39:53 +0100156
Alexander Evseeve704ca92018-09-11 11:30:55 +0200157 if (RELEASE_EBF_MIRRORS.toBoolean()) {
158 common.infoMsg("Promoting Emergency Bug Fix Debmirrors")
159 triggerEbfRepoJob(SOURCE_REVISION, TARGET_REVISION)
160 }
161
azvyagintsev87781882018-08-30 18:45:22 +0300162 if (RELEASE_DOCKER.toBoolean()) {
163 common.infoMsg("Promoting Docker images")
164 triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, TARGET_REVISION, DOCKER_IMAGES, SOURCE_REVISION)
165 }
Richard Felkl56082e92017-12-20 23:39:53 +0100166
azvyagintsev87781882018-08-30 18:45:22 +0300167 if (RELEASE_GIT.toBoolean()) {
168 common.infoMsg("Promoting Git repositories")
169 triggerGitTagJob(GIT_REPO_LIST, GIT_CREDENTIALS, TARGET_REVISION, SOURCE_REVISION)
Richard Felklc8c5a5a2018-04-19 17:06:30 +0200170
azvyagintsev87781882018-08-30 18:45:22 +0300171 }
172 if (RELEASE_VCP_IMAGES.toBoolean()) {
173 common.infoMsg("Promoting VCP images")
174 triggerPromoteVCPJob(VCP_IMAGE_LIST, TARGET_REVISION, SOURCE_REVISION)
175
176 }
azvyagintsev79778662018-11-23 18:07:16 +0200177 if (syncVcpImagesToS3.toBoolean()) {
Alexander Evseev1edde6b2018-10-30 15:22:44 +0300178 common.infoMsg("Syncing VCP images from internal: http://images.mcp.mirantis.net/ to s3: images.mirantis.com")
azvyagintsev79778662018-11-23 18:07:16 +0200179 triggerSyncVCPJob(VCP_IMAGE_LIST, TARGET_REVISION)
azvyagintsev759734c2018-10-03 13:57:54 +0300180 }
181 if (emailNotify) {
182 notify_text = "MCP Promotion ${env.SOURCE_REVISION} => ${env.TARGET_REVISION} has been done"
azvyagintsev87781882018-08-30 18:45:22 +0300183 emailext(to: NOTIFY_RECIPIENTS,
azvyagintsev759734c2018-10-03 13:57:54 +0300184 body: notify_text,
azvyagintsev87781882018-08-30 18:45:22 +0300185 subject: "MCP Promotion has been done")
186 }
187 }
188 } catch (Throwable e) {
Jakub Josefa63f9862018-01-11 17:58:38 +0100189 // If there was an error or exception thrown, the build failed
190 currentBuild.result = "FAILURE"
191 throw e
Richard Felkl37ee1e32017-12-11 10:01:39 +0100192 }
azvyagintsev87781882018-08-30 18:45:22 +0300193 }
194}