blob: 95e8bacef92d658be57cf7757cd403195b15c63a [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
19 */
20
Richard Felkl55175f52017-12-20 14:53:41 +010021common = new com.mirantis.mk.Common()
22git = new com.mirantis.mk.Git()
Richard Felkl37ee1e32017-12-11 10:01:39 +010023
24def triggerAptlyPromoteJob(aptlyUrl, components, diffOnly, dumpPublish, packages, recreate, source, storages, target){
25 build job: "aptly-promote-all-testing-stable", parameters: [
26 [$class: 'StringParameterValue', name: 'APTLY_URL', value: aptlyUrl],
27 [$class: 'StringParameterValue', name: 'COMPONENTS', value: components],
28 [$class: 'BooleanParameterValue', name: 'DIFF_ONLY', value: diffOnly],
29 [$class: 'BooleanParameterValue', name: 'DUMP_PUBLISH', value: dumpPublish],
30 [$class: 'StringParameterValue', name: 'PACKAGES', value: packages],
31 [$class: 'BooleanParameterValue', name: 'RECREATE', value: recreate],
32 [$class: 'StringParameterValue', name: 'SOURCE', value: source],
33 [$class: 'StringParameterValue', name: 'STORAGES', value: storages],
34 [$class: 'StringParameterValue', name: 'TARGET', value: target]
35 ]
36}
37
Richard Felkl56082e92017-12-20 23:39:53 +010038def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, targetTag, imageList) {
Richard Felkl55175f52017-12-20 14:53:41 +010039 build job: "docker-images-mirror", parameters: [
Richard Felkl37ee1e32017-12-11 10:01:39 +010040 [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials],
41 [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl],
Richard Felkl56082e92017-12-20 23:39:53 +010042 [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: targetTag],
Richard Felkl37ee1e32017-12-11 10:01:39 +010043 [$class: 'StringParameterValue', name: 'IMAGE_LIST', value: imageList]
44 ]
45}
46
Richard Felkl56082e92017-12-20 23:39:53 +010047def triggerMirrorRepoJob(snapshotId, snapshotName) {
48 build job: "mirror-snapshot-name-all", parameters: [
49 [$class: 'StringParameterValue', name: 'SNAPSHOT_NAME', value: snapshotName],
50 [$class: 'StringParameterValue', name: 'SNAPSHOT_ID', value: snapshotId]
51 ]
52}
53
Richard Felkl37ee1e32017-12-11 10:01:39 +010054def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){
Richard Felkl55175f52017-12-20 14:53:41 +010055 git.checkoutGitRepository(repoName, repoURL, "master", credentials)
Richard Felkl37ee1e32017-12-11 10:01:39 +010056 dir(repoName) {
Richard Felkl55175f52017-12-20 14:53:41 +010057 def checkTag = sh(script: "git tag -l ${tag}", returnStdout: true)
Richard Felkl37ee1e32017-12-11 10:01:39 +010058 if(checkTag == ""){
Richard Felkl55175f52017-12-20 14:53:41 +010059 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
60 }else{
61 def currentTagRef = sh(script: "git rev-list -n 1 ${tag}", returnStdout: true)
62 if(currentTagRef.equals(ref)){
63 common.infoMsg("Tag is already on the right ref")
64 return
65 }
66 else{
67 sshagent([credentials]) {
68 sh "git push --delete origin ${tag}"
69 }
70 sh "git tag --delete ${tag}"
71 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
72 }
Richard Felkl37ee1e32017-12-11 10:01:39 +010073 }
74 sshagent([credentials]) {
Richard Felkl55175f52017-12-20 14:53:41 +010075 sh "git push origin ${tag}"
Richard Felkl37ee1e32017-12-11 10:01:39 +010076 }
77 }
78}
Jakub Josefa63f9862018-01-11 17:58:38 +010079timeout(time: 12, unit: 'HOURS') {
80 node() {
81 try {
Richard Felkl56082e92017-12-20 23:39:53 +010082 stage("Promote"){
83 if(RELEASE_APTLY.toBoolean())
84 {
85 common.infoMsg("Promoting Aptly")
86 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, "(.*)/${SOURCE_REVISION}", APTLY_STORAGES, "{0}/${TARGET_REVISION}")
Richard Felkl37ee1e32017-12-11 10:01:39 +010087 }
Richard Felkl56082e92017-12-20 23:39:53 +010088
89 if(RELEASE_DEB_MIRRORS.toBoolean()){
90 common.infoMsg("Promoting Debmirrors")
91 triggerMirrorRepoJob(SOURCE_REVISION, TARGET_REVISION)
Jakub Josefa63f9862018-01-11 17:58:38 +010092 }
Richard Felkl56082e92017-12-20 23:39:53 +010093
94 if(RELEASE_DOCKER.toBoolean())
95 {
96 common.infoMsg("Promoting Docker images")
97 triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, TARGET_REVISION, DOCKER_IMAGES)
98 }
99
100 if(RELEASE_GIT.toBoolean())
101 {
102 common.infoMsg("Promoting Git repositories")
Jakub Josefa63f9862018-01-11 17:58:38 +0100103 def repos = GIT_REPO_LIST.tokenize('\n')
104 def repoUrl, repoName, repoCommit, repoArray
105 for (repo in repos){
106 if(repo.trim().indexOf(' ') == -1){
107 throw new IllegalArgumentException("Wrong format of repository and commit input")
108 }
109 repoArray = repo.trim().tokenize(' ')
110 repoName = repoArray[0]
111 repoUrl = repoArray[1]
112 repoCommit = repoArray[2]
Richard Felkl56082e92017-12-20 23:39:53 +0100113 gitRepoAddTag(repoUrl, repoName, TARGET_REVISION, GIT_CREDENTIALS, repoCommit)
Jakub Josefa63f9862018-01-11 17:58:38 +0100114 }
115 }
116 }
117 } catch (Throwable e) {
118 // If there was an error or exception thrown, the build failed
119 currentBuild.result = "FAILURE"
120 throw e
Richard Felkl37ee1e32017-12-11 10:01:39 +0100121 }
Richard Felkl37ee1e32017-12-11 10:01:39 +0100122 }
123}