blob: 52344d1ff3f3615e2cc92c035d8033ae87811788 [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
9 *
10 */
11
12common = new com.mirantis.mk.Common()
13git = new com.mirantis.mk.Git()
14
15def gitRepoAddTag(repoURL, repoName, tag, credentials, ref = "HEAD"){
16 git.checkoutGitRepository(repoName, repoURL, "master", credentials)
17 dir(repoName) {
Alexander Evseevc7eaf8c2018-05-10 14:47:09 +020018 sh "git tag -f -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
Richard Felklc8c5a5a2018-04-19 17:06:30 +020019 sshagent([credentials]) {
Alexander Evseev8fbe2bc2018-05-18 14:29:28 +020020 sh "git push -f origin ${tag}:refs/tags/${tag}"
Richard Felklc8c5a5a2018-04-19 17:06:30 +020021 }
22 }
23}
24
25timeout(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}