blob: 4abaf5d5ba9e57d4f5bce11c6eaab9f8f832dbcc [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
19def common = new com.mirantis.mk.Common()
20
21def triggerAptlyPromoteJob(aptlyUrl, components, diffOnly, dumpPublish, packages, recreate, source, storages, target){
22 build job: "aptly-promote-all-testing-stable", parameters: [
23 [$class: 'StringParameterValue', name: 'APTLY_URL', value: aptlyUrl],
24 [$class: 'StringParameterValue', name: 'COMPONENTS', value: components],
25 [$class: 'BooleanParameterValue', name: 'DIFF_ONLY', value: diffOnly],
26 [$class: 'BooleanParameterValue', name: 'DUMP_PUBLISH', value: dumpPublish],
27 [$class: 'StringParameterValue', name: 'PACKAGES', value: packages],
28 [$class: 'BooleanParameterValue', name: 'RECREATE', value: recreate],
29 [$class: 'StringParameterValue', name: 'SOURCE', value: source],
30 [$class: 'StringParameterValue', name: 'STORAGES', value: storages],
31 [$class: 'StringParameterValue', name: 'TARGET', value: target]
32 ]
33}
34
35def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, dockerRegistry, mcpVersion, imageList) {
36 build job: "mirror-docker-images", parameters: [
37 [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials],
38 [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl],
39 [$class: 'StringParameterValue', name: 'TARGET_REGISTRY', value: dockerRegistry],
40 [$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"){
46 git.checkoutGitRepository(repoName, repoURL, "master")
47 dir(repoName) {
48 def checkTag = sh "git tag -l ${tag}"
49 if(checkTag == ""){
50 sh 'git tag -a ${tag} ${ref} -m "Release of mcp version ${tag}"'
51 }
52 sshagent([credentials]) {
53 sh "git push origin master ${tag}"
54 }
55 }
56}
57
58node() {
59 try {
60 if(RELEASE_APTLY.toBoolean())
61 {
62 stage("Release Aptly"){
63 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/testing', APTLY_STORAGES, '{0}/stable')
64 triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/stable', APTLY_STORAGES, '{0}/${MCP_VERSION}')
65 }
66 }
67 if(RELEASE_DOCKER.toBoolean())
68 {
69 stage("Release Docker"){
70 triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, MCP_VERSION, DOCKER_IMAGES)
71 }
72 }
73 if(RELEASE_GIT.toBoolean())
74 {
75 stage("Release Git"){
76 def repos = GIT_REPO_LIST.tokenize('\n')
77 def repoUrl, repoName, repoCommit, repoArray
78 for (repo in repos){
79 if(repo.trim().indexOf(' ') == -1){
80 throw new IllegalArgumentException("Wrong format of repository and commit input")
81 }
82 repoArray = repo.trim().tokenize(' ')
83 repoName = repoArray[0]
84 repoUrl = repoArray[1]
85 repoCommit = repoArray[2]
86 gitRepoAddTag(repoUrl, repoName, MCP_VERSION, GIT_CREDENTIALS, repoCommit)
87 }
88 }
89 }
90 } catch (Throwable e) {
91 // If there was an error or exception thrown, the build failed
92 currentBuild.result = "FAILURE"
93 throw e
94 }
95}