Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Tag Git repositories |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * GIT_REPO_LIST |
| 7 | * GIT_CREDENTIALS |
| 8 | * TAG |
azvyagintsev | 971eeaf | 2018-07-26 21:57:08 +0200 | [diff] [blame] | 9 | * SOURCE_TAG initial commit\tag to be tagged with TAG |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 10 | * |
| 11 | */ |
| 12 | |
| 13 | common = new com.mirantis.mk.Common() |
| 14 | git = new com.mirantis.mk.Git() |
| 15 | |
| 16 | def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){ |
| 17 | git.checkoutGitRepository(repoName, repoURL, "master", credentials) |
| 18 | dir(repoName) { |
Alexander Evseev | c7eaf8c | 2018-05-10 14:47:09 +0200 | [diff] [blame] | 19 | sh "git tag -f -a ${tag} ${ref} -m \"Release of mcp version ${tag}\"" |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 20 | sshagent([credentials]) { |
Alexander Evseev | 8fbe2bc | 2018-05-18 14:29:28 +0200 | [diff] [blame] | 21 | sh "git push -f origin ${tag}:refs/tags/${tag}" |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | timeout(time: 12, unit: 'HOURS') { |
| 27 | node() { |
| 28 | try { |
| 29 | def repos = GIT_REPO_LIST.tokenize('\n') |
| 30 | def repoUrl, repoName, repoCommit, repoArray |
| 31 | for (repo in repos){ |
azvyagintsev | 721d813 | 2018-07-12 19:18:02 +0300 | [diff] [blame] | 32 | if(repo.startsWith('#')) |
| 33 | common.warningMsg("Skipping:" + repo.toString()) |
| 34 | continue |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 35 | if(repo.trim().indexOf(' ') == -1){ |
| 36 | throw new IllegalArgumentException("Wrong format of repository and commit input") |
| 37 | } |
| 38 | repoArray = repo.trim().tokenize(' ') |
| 39 | repoName = repoArray[0] |
| 40 | repoUrl = repoArray[1] |
| 41 | repoCommit = repoArray[2] |
azvyagintsev | 971eeaf | 2018-07-26 21:57:08 +0200 | [diff] [blame] | 42 | if (repoCommit.contains('SUBS_SOURCE_REF')) { |
| 43 | common.warningMsg("Replacing SUBS_SOURCE_REF => ${SOURCE_TAG}") |
| 44 | repoCommit.replace('SUBS_SOURCE_REF', SOURCE_TAG |
| 45 | ) |
| 46 | } |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 47 | gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit) |
| 48 | } |
| 49 | } catch (Throwable e) { |
| 50 | // If there was an error or exception thrown, the build failed |
| 51 | currentBuild.result = "FAILURE" |
| 52 | throw e |
| 53 | } |
| 54 | } |
azvyagintsev | 721d813 | 2018-07-12 19:18:02 +0300 | [diff] [blame] | 55 | } |