Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 1 | /** |
| 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 Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 19 | common = new com.mirantis.mk.Common() |
| 20 | git = new com.mirantis.mk.Git() |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 21 | |
| 22 | def 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 Felkl | b5ec176 | 2017-12-20 10:05:14 +0100 | [diff] [blame] | 36 | def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, mcpVersion, imageList) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 37 | build job: "docker-images-mirror", parameters: [ |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 38 | [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials], |
| 39 | [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl], |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 40 | [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: mcpVersion], |
| 41 | [$class: 'StringParameterValue', name: 'IMAGE_LIST', value: imageList] |
| 42 | ] |
| 43 | } |
| 44 | |
| 45 | def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){ |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 46 | git.checkoutGitRepository(repoName, repoURL, "master", credentials) |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 47 | dir(repoName) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 48 | def checkTag = sh(script: "git tag -l ${tag}", returnStdout: true) |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 49 | if(checkTag == ""){ |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 50 | 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 64 | } |
| 65 | sshagent([credentials]) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 66 | sh "git push origin ${tag}" |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 70 | timeout(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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 78 | } |
| 79 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame^] | 80 | 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 107 | } |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 108 | } |
| 109 | } |