Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 3 | * Promote MCP |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 4 | * |
| 5 | * Expected parameters: |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 6 | * SOURCE_REVISION |
| 7 | * TARGET_REVISION |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 8 | * RELEASE_APTLY |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 9 | * RELEASE_DEB_MIRRORS |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 10 | * 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 Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 21 | common = new com.mirantis.mk.Common() |
| 22 | git = new com.mirantis.mk.Git() |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 23 | |
| 24 | def 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 Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 38 | def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, targetTag, imageList) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 39 | build job: "docker-images-mirror", parameters: [ |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 40 | [$class: 'StringParameterValue', name: 'TARGET_REGISTRY_CREDENTIALS_ID', value: dockerCredentials], |
| 41 | [$class: 'StringParameterValue', name: 'REGISTRY_URL', value: dockerRegistryUrl], |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 42 | [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: targetTag], |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 43 | [$class: 'StringParameterValue', name: 'IMAGE_LIST', value: imageList] |
| 44 | ] |
| 45 | } |
| 46 | |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 47 | def 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 54 | def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){ |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 55 | git.checkoutGitRepository(repoName, repoURL, "master", credentials) |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 56 | dir(repoName) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 57 | def checkTag = sh(script: "git tag -l ${tag}", returnStdout: true) |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 58 | if(checkTag == ""){ |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 59 | 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 73 | } |
| 74 | sshagent([credentials]) { |
Richard Felkl | 55175f5 | 2017-12-20 14:53:41 +0100 | [diff] [blame] | 75 | sh "git push origin ${tag}" |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | timeout(time: 12, unit: 'HOURS') { |
| 80 | node() { |
| 81 | try { |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 82 | 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 87 | } |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 88 | |
| 89 | if(RELEASE_DEB_MIRRORS.toBoolean()){ |
| 90 | common.infoMsg("Promoting Debmirrors") |
| 91 | triggerMirrorRepoJob(SOURCE_REVISION, TARGET_REVISION) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 92 | } |
Richard Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 93 | |
| 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 Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 103 | 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 Felkl | 56082e9 | 2017-12-20 23:39:53 +0100 | [diff] [blame] | 113 | gitRepoAddTag(repoUrl, repoName, TARGET_REVISION, GIT_CREDENTIALS, repoCommit) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 114 | } |
| 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 Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 121 | } |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 122 | } |
| 123 | } |