blob: b2659445a48cb25af9e1596abba4a9f7ebfd8df9 [file] [log] [blame]
Richard Felkl37ee1e32017-12-11 10:01:39 +01001/**
2 *
3 * Release MCP
4 *
5 * Expected parameters:
6 * MCP_VERSION
7 * RELEASE_APTLY
8 * RELEASE_DOCKER
9 * RELEASE_GIT
10 * APTLY_URL
11 * APTLY_STORAGES
12 * DOCKER_CREDENTIALS
13 * DOCKER_URL
14 * DOCKER_IMAGES
15 * GIT_CREDENTIALS
16 * GIT_REPO_LIST
17 */
18
Richard Felkl55175f52017-12-20 14:53:41 +010019common = new com.mirantis.mk.Common()
20git = new com.mirantis.mk.Git()
Richard Felkl37ee1e32017-12-11 10:01:39 +010021
22def triggerAptlyPromoteJob(aptlyUrl, components, diffOnly, dumpPublish, packages, recreate, source, storages, target){
23 build job: "aptly-promote-all-testing-stable", parameters: [
24 [$class: 'StringParameterValue', name: 'APTLY_URL', value: aptlyUrl],
25 [$class: 'StringParameterValue', name: 'COMPONENTS', value: components],
26 [$class: 'BooleanParameterValue', name: 'DIFF_ONLY', value: diffOnly],
27 [$class: 'BooleanParameterValue', name: 'DUMP_PUBLISH', value: dumpPublish],
28 [$class: 'StringParameterValue', name: 'PACKAGES', value: packages],
29 [$class: 'BooleanParameterValue', name: 'RECREATE', value: recreate],
30 [$class: 'StringParameterValue', name: 'SOURCE', value: source],
31 [$class: 'StringParameterValue', name: 'STORAGES', value: storages],
32 [$class: 'StringParameterValue', name: 'TARGET', value: target]
33 ]
34}
35
Richard Felklb5ec1762017-12-20 10:05:14 +010036def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, mcpVersion, imageList) {
Richard Felkl55175f52017-12-20 14:53:41 +010037 build job: "docker-images-mirror", parameters: [
Richard Felkl37ee1e32017-12-11 10:01:39 +010038 [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials],
39 [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl],
Richard Felkl37ee1e32017-12-11 10:01:39 +010040 [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: mcpVersion],
41 [$class: 'StringParameterValue', name: 'IMAGE_LIST', value: imageList]
42 ]
43}
44
45def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){
Richard Felkl55175f52017-12-20 14:53:41 +010046 git.checkoutGitRepository(repoName, repoURL, "master", credentials)
Richard Felkl37ee1e32017-12-11 10:01:39 +010047 dir(repoName) {
Richard Felkl55175f52017-12-20 14:53:41 +010048 def checkTag = sh(script: "git tag -l ${tag}", returnStdout: true)
Richard Felkl37ee1e32017-12-11 10:01:39 +010049 if(checkTag == ""){
Richard Felkl55175f52017-12-20 14:53:41 +010050 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
51 }else{
52 def currentTagRef = sh(script: "git rev-list -n 1 ${tag}", returnStdout: true)
53 if(currentTagRef.equals(ref)){
54 common.infoMsg("Tag is already on the right ref")
55 return
56 }
57 else{
58 sshagent([credentials]) {
59 sh "git push --delete origin ${tag}"
60 }
61 sh "git tag --delete ${tag}"
62 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
63 }
Richard Felkl37ee1e32017-12-11 10:01:39 +010064 }
65 sshagent([credentials]) {
Richard Felkl55175f52017-12-20 14:53:41 +010066 sh "git push origin ${tag}"
Richard Felkl37ee1e32017-12-11 10:01:39 +010067 }
68 }
69}
Jakub Josefa63f9862018-01-11 17:58:38 +010070timeout(time: 12, unit: 'HOURS') {
71 node() {
72 try {
73 if(RELEASE_APTLY.toBoolean())
74 {
75 stage("Release Aptly"){
76 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/testing', APTLY_STORAGES, '{0}/stable')
77 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/stable', APTLY_STORAGES, '{0}/${MCP_VERSION}')
Richard Felkl37ee1e32017-12-11 10:01:39 +010078 }
79 }
Jakub Josefa63f9862018-01-11 17:58:38 +010080 if(RELEASE_DOCKER.toBoolean())
81 {
82 stage("Release Docker"){
83 triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, MCP_VERSION, DOCKER_IMAGES)
84 }
85 }
86 if(RELEASE_GIT.toBoolean())
87 {
88 stage("Release Git"){
89 def repos = GIT_REPO_LIST.tokenize('\n')
90 def repoUrl, repoName, repoCommit, repoArray
91 for (repo in repos){
92 if(repo.trim().indexOf(' ') == -1){
93 throw new IllegalArgumentException("Wrong format of repository and commit input")
94 }
95 repoArray = repo.trim().tokenize(' ')
96 repoName = repoArray[0]
97 repoUrl = repoArray[1]
98 repoCommit = repoArray[2]
99 gitRepoAddTag(repoUrl, repoName, MCP_VERSION, GIT_CREDENTIALS, repoCommit)
100 }
101 }
102 }
103 } catch (Throwable e) {
104 // If there was an error or exception thrown, the build failed
105 currentBuild.result = "FAILURE"
106 throw e
Richard Felkl37ee1e32017-12-11 10:01:39 +0100107 }
Richard Felkl37ee1e32017-12-11 10:01:39 +0100108 }
109}