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}") |
Alexander Evseev | 65f2f5b | 2018-10-08 17:38:03 +0200 | [diff] [blame] | 19 | checkout([ |
| 20 | $class: 'GitSCM', |
| 21 | branches: [ |
| 22 | [name: 'FETCH_HEAD'], |
| 23 | ], |
| 24 | userRemoteConfigs: [ |
| 25 | [url: repoURL, refspec: ref, credentialsId: credentials], |
| 26 | ], |
| 27 | extensions: [ |
| 28 | [$class: 'PruneStaleBranch'], |
| 29 | [$class: 'RelativeTargetDirectory', relativeTargetDir: repoName], |
| 30 | [$class: 'SubmoduleOption', disableSubmodules: true], |
| 31 | [$class: 'UserIdentity', name: 'MCP CI', email: 'ci+infra@mirantis.com'], |
| 32 | ], |
| 33 | ]) |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 34 | dir(repoName) { |
Alexander Evseev | ae6249f | 2018-10-08 18:31:19 +0200 | [diff] [blame] | 35 | sh "git tag -f -a ${tag} -m \"Release of mcp version ${tag}\"" |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 36 | sshagent([credentials]) { |
| 37 | sh "git push -f origin ${tag}:refs/tags/${tag}" |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 38 | } |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 39 | } |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | timeout(time: 12, unit: 'HOURS') { |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 43 | node() { |
| 44 | try { |
| 45 | def repos = GIT_REPO_LIST.tokenize('\n') |
| 46 | def repoUrl, repoName, repoCommit, repoArray |
| 47 | for (repo in repos){ |
| 48 | if(repo.startsWith('#')){ |
| 49 | common.warningMsg("Skipping repo ${repo}") |
| 50 | continue |
| 51 | } |
| 52 | if(repo.trim().indexOf(' ') == -1){ |
| 53 | throw new IllegalArgumentException("Wrong format of repository and commit input") |
| 54 | } |
| 55 | repoArray = repo.trim().tokenize(' ') |
| 56 | repoName = repoArray[0] |
| 57 | repoUrl = repoArray[1] |
| 58 | repoCommit = repoArray[2] |
| 59 | if (repoCommit.contains('SUBS_SOURCE_REF')) { |
| 60 | common.warningMsg("Replacing SUBS_SOURCE_REF => ${SOURCE_TAG}") |
azvyagintsev | d79593d | 2018-08-14 15:58:23 +0300 | [diff] [blame] | 61 | repoCommit = repoCommit.replace('SUBS_SOURCE_REF', SOURCE_TAG |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 62 | ) |
| 63 | } |
| 64 | gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit) |
| 65 | } |
| 66 | } catch (Throwable e) { |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 67 | // If there was an error or exception thrown, the build failed |
| 68 | currentBuild.result = "FAILURE" |
| 69 | throw e |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 70 | } |
Richard Felkl | c8c5a5a | 2018-04-19 17:06:30 +0200 | [diff] [blame] | 71 | } |
azvyagintsev | 3280a0c | 2018-07-31 08:44:43 +0200 | [diff] [blame] | 72 | } |