blob: 68229a6571ad7686af4f4698136c8ac46e6e6d1f [file] [log] [blame]
Richard Felklc8c5a5a2018-04-19 17:06:30 +02001/**
2 *
3 * Tag Git repositories
4 *
5 * Expected parameters:
6 * GIT_REPO_LIST
7 * GIT_CREDENTIALS
8 * TAG
azvyagintsev971eeaf2018-07-26 21:57:08 +02009 * SOURCE_TAG initial commit\tag to be tagged with TAG
Richard Felklc8c5a5a2018-04-19 17:06:30 +020010 *
11 */
12
13common = new com.mirantis.mk.Common()
14git = new com.mirantis.mk.Git()
15
16def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){
17 git.checkoutGitRepository(repoName, repoURL, "master", credentials)
18 dir(repoName) {
Alexander Evseevc7eaf8c2018-05-10 14:47:09 +020019 sh "git tag -f -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
Richard Felklc8c5a5a2018-04-19 17:06:30 +020020 sshagent([credentials]) {
Alexander Evseev8fbe2bc2018-05-18 14:29:28 +020021 sh "git push -f origin ${tag}:refs/tags/${tag}"
Richard Felklc8c5a5a2018-04-19 17:06:30 +020022 }
23 }
24}
25
26timeout(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){
azvyagintsev721d8132018-07-12 19:18:02 +030032 if(repo.startsWith('#'))
33 common.warningMsg("Skipping:" + repo.toString())
34 continue
Richard Felklc8c5a5a2018-04-19 17:06:30 +020035 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]
azvyagintsev971eeaf2018-07-26 21:57:08 +020042 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 Felklc8c5a5a2018-04-19 17:06:30 +020047 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 }
azvyagintsev721d8132018-07-12 19:18:02 +030055}