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 |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | common = new com.mirantis.mk.Common() |
| 13 | git = new com.mirantis.mk.Git() |
| 14 | |
| 15 | def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){ |
| 16 | git.checkoutGitRepository(repoName, repoURL, "master", credentials) |
| 17 | dir(repoName) { |
Alexander Evseev | c7eaf8c | 2018-05-10 14:47:09 +0200 | [diff] [blame^] | 18 | 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] | 19 | sshagent([credentials]) { |
| 20 | sh "git push origin ${tag}" |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | timeout(time: 12, unit: 'HOURS') { |
| 26 | node() { |
| 27 | try { |
| 28 | def repos = GIT_REPO_LIST.tokenize('\n') |
| 29 | def repoUrl, repoName, repoCommit, repoArray |
| 30 | for (repo in repos){ |
| 31 | if(repo.trim().indexOf(' ') == -1){ |
| 32 | throw new IllegalArgumentException("Wrong format of repository and commit input") |
| 33 | } |
| 34 | repoArray = repo.trim().tokenize(' ') |
| 35 | repoName = repoArray[0] |
| 36 | repoUrl = repoArray[1] |
| 37 | repoCommit = repoArray[2] |
| 38 | gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit) |
| 39 | } |
| 40 | } catch (Throwable e) { |
| 41 | // If there was an error or exception thrown, the build failed |
| 42 | currentBuild.result = "FAILURE" |
| 43 | throw e |
| 44 | } |
| 45 | } |
| 46 | } |