blob: 373e0298dcd2cae73b0717fac75590eabd962bf1 [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) {
18 def checkTag = sh(script: "git tag -l ${tag}", returnStdout: true)
19 if(checkTag == ""){
20 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
21 }else{
22 def currentTagRef = sh(script: "git rev-list -n 1 ${tag}", returnStdout: true)
23 if(currentTagRef.equals(ref)){
24 common.infoMsg("Tag is already on the right ref")
25 return
26 }
27 else{
28 sshagent([credentials]) {
29 sh "git push --delete origin ${tag}"
30 }
31 sh "git tag --delete ${tag}"
32 sh "git tag -a ${tag} ${ref} -m \"Release of mcp version ${tag}\""
33 }
34 }
35 sshagent([credentials]) {
36 sh "git push origin ${tag}"
37 }
38 }
39}
40
41timeout(time: 12, unit: 'HOURS') {
42 node() {
43 try {
44 def repos = GIT_REPO_LIST.tokenize('\n')
45 def repoUrl, repoName, repoCommit, repoArray
46 for (repo in repos){
47 if(repo.trim().indexOf(' ') == -1){
48 throw new IllegalArgumentException("Wrong format of repository and commit input")
49 }
50 repoArray = repo.trim().tokenize(' ')
51 repoName = repoArray[0]
52 repoUrl = repoArray[1]
53 repoCommit = repoArray[2]
54 gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit)
55 }
56 } catch (Throwable e) {
57 // If there was an error or exception thrown, the build failed
58 currentBuild.result = "FAILURE"
59 throw e
60 }
61 }
62}