blob: 7baeb2266d8b5cc721309164dd3d8278fa594f5a [file] [log] [blame]
Ruslan Gustomiasovda4edd62019-06-25 14:26:28 +02001package com.mirantis.mk
2
3/**
4 * ReleaseWorkflow functions
5 *
6 */
7
8/**
9 * Update release metadata after image build
10 */
11
Ruslan Gustomiasov9340faa2019-06-25 16:59:31 +020012def updateReleaseMetadata(){
Ruslan Gustomiasovda4edd62019-06-25 14:26:28 +020013 def python = new com.mirantis.mk.Python()
14 def gerrit = new com.mirantis.mk.Gerrit()
15 def git = new com.mirantis.mk.Git()
16 def changeAuthorName = "MCP-CI"
17 def changeAuthorEmail = "mcp-ci-jenkins@ci.mcp.mirantis.net"
18 def cred = common.getCredentials(env["CREDENTIALS_ID"], 'key')
19 String gerritUser = cred.username
20 def gerritHost = env["METADATA_REPO_URL.tokenize"]('@')[-1].tokenize(':')[0]
21 def metadataProject = env["METADATA_REPO_URL"].tokenize('/')[-2..-1].join('/')
22 def gerritPort = env["METADATA_REPO_URL"].tokenize(':')[-1].tokenize('/')[0]
23 def workspace = common.getWorkspace()
24 def venvDir = "${workspace}/gitreview-venv"
25 def repoDir = "${venvDir}/repo"
26 def metadataDir = "${repoDir}/metadata"
27 def imageChangeId
28 def commitMessage
29 def gitRemote
30 if (env["RELEASE_METADATA_CR"].toBoolean()) {
31 stage("Installing virtualenv") {
32 python.setupVirtualenv(venvDir, 'python3', ['git-review', 'PyYaml'])
33 }
34
35 stage('Cleanup repo dir') {
36 dir(repoDir) {
37 deleteDir()
38 }
39 }
40 stage('Cloning release-metadata repository') {
Ruslan Gustomiasov9340faa2019-06-25 16:59:31 +020041 git.checkoutGitRepository(repoDir, METADATA_REPO_URL, METADATA_GERRIT_BRANCH, CREDENTIALS_ID, true, 10, 0)
Ruslan Gustomiasovda4edd62019-06-25 14:26:28 +020042 dir(repoDir) {
43 gitRemote = sh(
44 script:
45 'git remote -v | head -n1 | cut -f1',
46 returnStdout: true,
47 ).trim()
48 }
49 }
50 stage('Creating CRs') {
51 for (openstackRelease in resultBuiltImages.keySet()) {
52 def crTopic = "nightly_update_images_" + openstackRelease
53 //Check if CR already exist
54
55 def gerritAuth = ['PORT': gerritPort, 'USER': gerritUser, 'HOST': gerritHost]
56 def changeParams = ['owner': gerritUser, 'status': 'open', 'project': metadataProject, 'branch': env["METADATA_GERRIT_BRANCH"], 'topic': crTopic]
57 def gerritChange = gerrit.findGerritChange(env["CREDENTIALS_ID"], gerritAuth, changeParams)
58
59 git.changeGitBranch(repoDir, env["METADATA_GERRIT_BRANCH"])
60 if (gerritChange) {
61 def jsonChange = readJSON text: gerritChange
62 changeNum = jsonChange['number']
63 imageChangeId = 'Change-Id: '
64 imageChangeId += jsonChange['id']
65 //get existent change from gerrit
66 gerrit.getGerritChangeByNum(env["CREDENTIALS_ID"], venvDir, repoDir, gitRemote, changeNum)
67 } else {
68 imageChangeId = ''
69 git.createGitBranch(repoDir, crTopic)
70 }
71
72 for (component in resultBuiltImages[openstackRelease].keySet()) {
73 resultBuiltImages[openstackRelease][component].each {
Ruslan Gustomiasov9340faa2019-06-25 16:59:31 +020074 //runReleaseMetadataApp(venvDir, repoDir, metadataDir, "update", "images:openstack:${openstackRelease}:${component}:${it.key}", "${it.value}")
75 cmdText = "python ${repoDir}/utils/app.py --path ${metadataDir} update --key images:openstack:${openstackRelease}:${component}:${it.key} --value ${it.value}"
Ruslan Gustomiasovda4edd62019-06-25 14:26:28 +020076 python.runVirtualenvCommand(venvDir, cmdText)
77 }
78 }
79
80 commitMessage =
81 """[oscore] Auto-update ${metadataProject}
82
83 |${imageChangeId}
84 """.stripMargin()
85 //commit change
86 if (gerritChange) {
87 git.commitGitChanges(repoDir, commitMessage, changeAuthorEmail, changeAuthorName, false, true)
88 } else {
89 git.commitGitChanges(repoDir, commitMessage, changeAuthorEmail, changeAuthorName, false)
90 }
91 //post change
92 gerrit.postGerritReview(CREDENTIALS_ID, venvDir, repoDir, changeAuthorName, changeAuthorEmail, gitRemote, crTopic, METADATA_GERRIT_BRANCH)
93
94 }
95 }
96 }
97}