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 | |
| 19 | def common = new com.mirantis.mk.Common() |
| 20 | |
| 21 | def 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 | |
Richard Felkl | b5ec176 | 2017-12-20 10:05:14 +0100 | [diff] [blame^] | 35 | def triggerDockerMirrorJob(dockerCredentials, dockerRegistryUrl, mcpVersion, imageList) { |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 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], |
Richard Felkl | 37ee1e3 | 2017-12-11 10:01:39 +0100 | [diff] [blame] | 39 | [$class: 'StringParameterValue', name: 'IMAGE_TAG', value: mcpVersion], |
| 40 | [$class: 'StringParameterValue', name: 'IMAGE_LIST', value: imageList] |
| 41 | ] |
| 42 | } |
| 43 | |
| 44 | def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){ |
| 45 | git.checkoutGitRepository(repoName, repoURL, "master") |
| 46 | dir(repoName) { |
| 47 | def checkTag = sh "git tag -l ${tag}" |
| 48 | if(checkTag == ""){ |
| 49 | sh 'git tag -a ${tag} ${ref} -m "Release of mcp version ${tag}"' |
| 50 | } |
| 51 | sshagent([credentials]) { |
| 52 | sh "git push origin master ${tag}" |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | node() { |
| 58 | try { |
| 59 | if(RELEASE_APTLY.toBoolean()) |
| 60 | { |
| 61 | stage("Release Aptly"){ |
| 62 | triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/testing', APTLY_STORAGES, '{0}/stable') |
| 63 | triggerAptlyPromoteJob(APTLY_URL, 'all', false, true, 'all', false, '(.*)/stable', APTLY_STORAGES, '{0}/${MCP_VERSION}') |
| 64 | } |
| 65 | } |
| 66 | if(RELEASE_DOCKER.toBoolean()) |
| 67 | { |
| 68 | stage("Release Docker"){ |
| 69 | triggerDockerMirrorJob(DOCKER_CREDENTIALS, DOCKER_URL, MCP_VERSION, DOCKER_IMAGES) |
| 70 | } |
| 71 | } |
| 72 | if(RELEASE_GIT.toBoolean()) |
| 73 | { |
| 74 | stage("Release Git"){ |
| 75 | def repos = GIT_REPO_LIST.tokenize('\n') |
| 76 | def repoUrl, repoName, repoCommit, repoArray |
| 77 | for (repo in repos){ |
| 78 | if(repo.trim().indexOf(' ') == -1){ |
| 79 | throw new IllegalArgumentException("Wrong format of repository and commit input") |
| 80 | } |
| 81 | repoArray = repo.trim().tokenize(' ') |
| 82 | repoName = repoArray[0] |
| 83 | repoUrl = repoArray[1] |
| 84 | repoCommit = repoArray[2] |
| 85 | gitRepoAddTag(repoUrl, repoName, MCP_VERSION, GIT_CREDENTIALS, repoCommit) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } catch (Throwable e) { |
| 90 | // If there was an error or exception thrown, the build failed |
| 91 | currentBuild.result = "FAILURE" |
| 92 | throw e |
| 93 | } |
| 94 | } |