blob: 312ec9e7aa35b133e0dc392f17beaf4f3700be03 [file] [log] [blame]
azvyagintsev3280a0c2018-07-31 08:44:43 +02001
Richard Felklc8c5a5a2018-04-19 17:06:30 +02002/**
azvyagintsev3280a0c2018-07-31 08:44:43 +02003*
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 Felklc8c5a5a2018-04-19 17:06:30 +020013
14common = new com.mirantis.mk.Common()
15git = new com.mirantis.mk.Git()
16
17def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){
azvyagintsev3280a0c2018-07-31 08:44:43 +020018 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 Felklc8c5a5a2018-04-19 17:06:30 +020024 }
azvyagintsev3280a0c2018-07-31 08:44:43 +020025 }
Richard Felklc8c5a5a2018-04-19 17:06:30 +020026}
27
28timeout(time: 12, unit: 'HOURS') {
azvyagintsev3280a0c2018-07-31 08:44:43 +020029 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}")
azvyagintsevd79593d2018-08-14 15:58:23 +030047 repoCommit = repoCommit.replace('SUBS_SOURCE_REF', SOURCE_TAG
azvyagintsev3280a0c2018-07-31 08:44:43 +020048 )
49 }
50 gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit)
51 }
52 } catch (Throwable e) {
Richard Felklc8c5a5a2018-04-19 17:06:30 +020053 // If there was an error or exception thrown, the build failed
54 currentBuild.result = "FAILURE"
55 throw e
azvyagintsev3280a0c2018-07-31 08:44:43 +020056 }
Richard Felklc8c5a5a2018-04-19 17:06:30 +020057 }
azvyagintsev3280a0c2018-07-31 08:44:43 +020058 }