blob: 68fcdcdd54f9e7707192aa62a4ed1ddb18f60518 [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}")
Alexander Evseev65f2f5b2018-10-08 17:38:03 +020019 checkout([
20 $class: 'GitSCM',
21 branches: [
22 [name: 'FETCH_HEAD'],
23 ],
24 userRemoteConfigs: [
25 [url: repoURL, refspec: ref, credentialsId: credentials],
26 ],
27 extensions: [
28 [$class: 'PruneStaleBranch'],
29 [$class: 'RelativeTargetDirectory', relativeTargetDir: repoName],
30 [$class: 'SubmoduleOption', disableSubmodules: true],
31 [$class: 'UserIdentity', name: 'MCP CI', email: 'ci+infra@mirantis.com'],
32 ],
33 ])
azvyagintsev3280a0c2018-07-31 08:44:43 +020034 dir(repoName) {
Alexander Evseevae6249f2018-10-08 18:31:19 +020035 sh "git tag -f -a ${tag} -m \"Release of mcp version ${tag}\""
azvyagintsev3280a0c2018-07-31 08:44:43 +020036 sshagent([credentials]) {
37 sh "git push -f origin ${tag}:refs/tags/${tag}"
Richard Felklc8c5a5a2018-04-19 17:06:30 +020038 }
azvyagintsev3280a0c2018-07-31 08:44:43 +020039 }
Richard Felklc8c5a5a2018-04-19 17:06:30 +020040}
41
42timeout(time: 12, unit: 'HOURS') {
azvyagintsev3280a0c2018-07-31 08:44:43 +020043 node() {
44 try {
45 def repos = GIT_REPO_LIST.tokenize('\n')
46 def repoUrl, repoName, repoCommit, repoArray
47 for (repo in repos){
48 if(repo.startsWith('#')){
49 common.warningMsg("Skipping repo ${repo}")
50 continue
51 }
52 if(repo.trim().indexOf(' ') == -1){
53 throw new IllegalArgumentException("Wrong format of repository and commit input")
54 }
55 repoArray = repo.trim().tokenize(' ')
56 repoName = repoArray[0]
57 repoUrl = repoArray[1]
58 repoCommit = repoArray[2]
59 if (repoCommit.contains('SUBS_SOURCE_REF')) {
60 common.warningMsg("Replacing SUBS_SOURCE_REF => ${SOURCE_TAG}")
azvyagintsevd79593d2018-08-14 15:58:23 +030061 repoCommit = repoCommit.replace('SUBS_SOURCE_REF', SOURCE_TAG
azvyagintsev3280a0c2018-07-31 08:44:43 +020062 )
63 }
64 gitRepoAddTag(repoUrl, repoName, TAG, GIT_CREDENTIALS, repoCommit)
65 }
66 } catch (Throwable e) {
Richard Felklc8c5a5a2018-04-19 17:06:30 +020067 // If there was an error or exception thrown, the build failed
68 currentBuild.result = "FAILURE"
69 throw e
azvyagintsev3280a0c2018-07-31 08:44:43 +020070 }
Richard Felklc8c5a5a2018-04-19 17:06:30 +020071 }
azvyagintsev3280a0c2018-07-31 08:44:43 +020072 }