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