blob: bb3f7a5fad027018c18665fa64c7c798d6a96b5e [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){
32 if(repo.trim().indexOf(' ') == -1){
33 throw new IllegalArgumentException("Wrong format of repository and commit input")
34 }
35 repoArray = repo.trim().tokenize(' ')
36 repoName = repoArray[0]
37 repoUrl = repoArray[1]
38 repoCommit = repoArray[2]
azvyagintsev971eeaf2018-07-26 21:57:08 +020039 if (repoCommit.contains('SUBS_SOURCE_REF')) {
40 common.warningMsg("Replacing SUBS_SOURCE_REF => ${SOURCE_TAG}")
41 repoCommit.replace('SUBS_SOURCE_REF', SOURCE_TAG
42 )
43 }
Richard Felklc8c5a5a2018-04-19 17:06:30 +020044 gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit)
45 }
46 } catch (Throwable e) {
47 // If there was an error or exception thrown, the build failed
48 currentBuild.result = "FAILURE"
49 throw e
50 }
51 }
52}