azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Build mirror/aptly/apt01 image pipeline |
| 4 | * |
| 5 | * PACKER_URL = 'https://releases.hashicorp.com/packer/1.2.4/packer_1.2.4_linux_amd64.zip' |
| 6 | * PACKER_ZIP_MD5 = '997274e80ae41102eecf9df2e5b67860' |
| 7 | * PACKER_ARGS = '-debug' |
| 8 | * BUILD_ONLY = 'openstack|qemu' |
| 9 | * CLEANUP_AFTER = wipe workspace AFTER build |
| 10 | * IMAGE_NAME = Name of the result image. |
| 11 | * TIMESTAMP_INAME = True|false. If true - image will be uploaded to backend with IMAGE_NAME + timestamp |
| 12 | * |
| 13 | * OPENSTACK_OPENRC_YAML: aml of key:value variables required for openstack venv |
| 14 | * example: |
| 15 | * --- |
| 16 | * OS_TENANT_ID: 'xxxx' |
| 17 | * OS_TENANT_NAME: "mcp-oscore-ci" |
| 18 | * |
| 19 | * EXTRA_VARIABLES_YAML - Yaml of key:value variables required for template.json |
| 20 | * example: |
| 21 | * --- |
| 22 | * IMAGE_NAME: 'ubuntu-16.04-proposed' |
| 23 | * |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 24 | * CREDENTIALS_ID = Global jenkins cred for clone DEFAULT_GIT_URL |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 25 | * DEFAULT_GIT_URL |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 26 | * REFSPEC |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 27 | * |
| 28 | * OS_VERSION = OpenStack version |
| 29 | * OS_CREDENTIALS_ID = ID of credentials for OpenStack API stored in Jenkins. |
| 30 | * OS_URL = Keystone auth endpoint of the OpenStack. |
| 31 | * OS_PROJECT = |
| 32 | * |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 33 | * PUBLISH_BACKEND = local,glance,http |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 34 | * UPLOAD_URL = URL of an WebDAV used to upload the image after creating.(Only in case PUBLISH_BACKEND == http) |
| 35 | */ |
| 36 | |
| 37 | // Load shared libs |
| 38 | def common = new com.mirantis.mk.Common() |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 39 | def openstack = new com.mirantis.mk.Openstack() |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 40 | def gerrit = new com.mirantis.mk.Gerrit() |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 41 | def date = new Date() |
| 42 | def dateTime = date.format("ddMMyyyy-HHmmss") |
| 43 | // |
| 44 | def job_env = env.getEnvironment().findAll { k, v -> v } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 45 | gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit' |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 46 | |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 47 | ///// |
| 48 | extra_vars = readYaml text: job_env.get('EXTRA_VARIABLES_YAML','').trim() |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 49 | // FIXME: os_openrc should be refactored. |
| 50 | os_openrc = readYaml text: job_env.get('OPENSTACK_OPENRC_YAML','').trim() |
azvyagintsev | 4f9239d | 2018-07-18 16:47:15 +0300 | [diff] [blame] | 51 | if (job_env.get('TIMESTAMP_INAME', false).toBoolean()) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 52 | imageName = job_env.IMAGE_NAME + "-" + dateTime |
| 53 | } else { |
| 54 | imageName = job_env.IMAGE_NAME |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 55 | } |
| 56 | // Overwrite IMAGE_NAME in template.json with expected |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 57 | extra_vars['IMAGE_NAME'] = imageName |
azvyagintsev | 4f9239d | 2018-07-18 16:47:15 +0300 | [diff] [blame] | 58 | // Fix some variables |
| 59 | job_env['CLEANUP_AFTER'] = job_env.CLEANUP_AFTER.toBoolean() |
| 60 | job_env['SKIP_UPLOAD'] = job_env.SKIP_UPLOAD.toBoolean() |
| 61 | job_env['CLEANUP_AFTER'] = job_env.CLEANUP_AFTER.toBoolean() |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 62 | job_env['BUILD_ONLY'] = job_env.BUILD_ONLY.toLowerCase() |
| 63 | job_env['PUBLISH_BACKEND'] = job_env.PUBLISH_BACKEND.toLowerCase() |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 64 | publishBackends = job_env['PUBLISH_BACKEND'].split(',') |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 65 | // |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 66 | defaultGitRef = job_env.get('REFSPEC', 'HEAD') |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 67 | defaultGitUrl = job_env.get('DEFAULT_GIT_URL', null) |
Denis Egorenko | 3d9dfb2 | 2019-03-01 19:18:25 +0400 | [diff] [blame] | 68 | slaveNode = (env.SLAVE_NODE ?: 'virtual') |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 69 | |
| 70 | // Self-check |
| 71 | for (String req_v : ['BUILD_OS', 'BUILD_ONLY','IMAGE_NAME'] ) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 72 | if (!job_env.get(req_v, false)) { |
| 73 | throw new Exception("${req_v} not set!") |
| 74 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | def MapToList(input_map) { |
| 78 | /** |
| 79 | * Convert dict in bash-like list |
| 80 | */ |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 81 | def data_list = [] |
| 82 | for (i = 0; i < input_map.size(); i++) { |
| 83 | data = '' |
| 84 | data = input_map.keySet()[i] + "=" + input_map.values()[i] |
| 85 | data_list.add(data) |
| 86 | } |
| 87 | return data_list |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | timeout(time: 6, unit: 'HOURS') { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 91 | node(slaveNode) { |
| 92 | def workspace = common.getWorkspace() |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 93 | def openstackEnv = "${workspace}/venv" |
| 94 | def rcFile = '' |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 95 | creds = common.getPasswordCredentials(job_env.CREDENTIALS_ID) |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 96 | |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 97 | stage("checkout") { |
| 98 | if (defaultGitRef && defaultGitUrl) { |
| 99 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", job_env.CREDENTIALS_ID) |
| 100 | } else { |
| 101 | throw new Exception("Cannot checkout gerrit patchset: DEFAULT_GIT_URL is null") |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 102 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 103 | } |
| 104 | |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 105 | if (job_env.BUILD_ONLY == 'openstack' || 'glance' in publishBackends) { |
| 106 | rcFile = openstack.createOpenstackEnv(workspace, os_openrc['OS_AUTH_URL'], os_openrc['OS_CREDENTIALS_ID'], os_openrc['OS_PROJECT_NAME'], "default", "", "default", "3", "") |
| 107 | } |
| 108 | |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 109 | try { |
| 110 | def _artifact_dir = "${workspace}/artifacts" |
| 111 | def _artifact_list = [] |
| 112 | def ImagesCacheFolder = "${workspace}/../${env.JOB_NAME}_cache/" |
| 113 | stage("Prepare env") { |
| 114 | if (!fileExists("${workspace}/tmp")) { |
| 115 | sh "mkdir -p ${workspace}/tmp" |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 116 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 117 | if (!fileExists(ImagesCacheFolder)) { |
| 118 | sh "mkdir -p ${ImagesCacheFolder}" |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 119 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 120 | if (!fileExists(_artifact_dir)) { |
| 121 | sh "mkdir -p ${_artifact_dir}" |
| 122 | } |
| 123 | if (!fileExists("bin")) { |
| 124 | common.infoMsg("Downloading packer") |
| 125 | sh "mkdir -p bin" |
| 126 | dir("bin") { |
| 127 | def zipname = sh(script: "basename ${job_env.PACKER_URL}", returnStdout: true).trim() |
| 128 | sh(script: "wget --quiet ${job_env.PACKER_URL}", returnStdout: true) |
| 129 | sh "echo \"${job_env.PACKER_ZIP_MD5} ${zipname}\" >> md5sum" |
| 130 | sh(script: "md5sum -c --status md5sum", returnStdout: true) |
| 131 | sh "unzip ${zipname}" |
| 132 | } |
| 133 | } |
| 134 | if (!fileExists("${job_env.BUILD_OS}/images")) { |
| 135 | // clean images dir before building |
| 136 | sh(script: "rm -rf ${job_env.BUILD_OS}/images/*", returnStatus: true) |
| 137 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 138 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 139 | |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 140 | stage("Build Instance") { |
Aleksey Zvyagintsev | 42e7695 | 2018-12-14 13:40:44 +0000 | [diff] [blame] | 141 | def _packer_args = job_env.get('PACKER_ARGS', '') |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 142 | def _packer_log = "${workspace}/packer.log" |
| 143 | // clean old log, for correct status grepping |
| 144 | if (fileExists(_packer_log)) { |
| 145 | sh "rm -v ${_packer_log}" |
| 146 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 147 | |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 148 | dir("${workspace}/${job_env.BUILD_OS}/") { |
| 149 | if (fileExists("config-drive")) { |
| 150 | def model = extra_vars.get('CLUSTER_MODEL', '') |
| 151 | if (model != "") { |
| 152 | checkout([ |
| 153 | $class : 'GitSCM', |
| 154 | branches : [[name: 'FETCH_HEAD']], |
| 155 | recursiveSubmodules: true, |
| 156 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'config-drive/model']], |
| 157 | userRemoteConfigs : [[url: model, refspec: extra_vars.get('CLUSTER_MODEL_REF', 'master'), credentialsId: gerritCredentials]] |
| 158 | ]) |
Denis Egorenko | 34d326c | 2019-02-11 20:50:53 +0400 | [diff] [blame] | 159 | |
| 160 | def clusterName = extra_vars.get('CLUSTER_NAME', '') |
| 161 | def mcpVersion = extra_vars.get('MCP_VERSION', '') |
| 162 | if (clusterName == 'mcp-offline' && mcpVersion != '') { |
| 163 | def filePath = 'classes/cluster/mcp-offline/infra/apt01_dummy.yml' |
| 164 | sh "sed -i 's/mcp_version: .*/mcp_version: ${mcpVersion}/' config-drive/model/${filePath}" |
| 165 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 166 | } |
| 167 | def scripts = extra_vars.get('GIT_SALT_FORMULAS_SCRIPTS', '') |
| 168 | if (scripts != "") { |
| 169 | checkout([ |
| 170 | $class : 'GitSCM', |
| 171 | branches : [[name: 'FETCH_HEAD']], |
| 172 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'config-drive/salt_scripts']], |
| 173 | userRemoteConfigs: [[url: scripts, refspec: extra_vars.get('SCRIPTS_REF', 'master'), credentialsId: gerritCredentials]] |
| 174 | ]) |
| 175 | } |
| 176 | |
| 177 | common.infoMsg("Creating cloud-config drive") |
| 178 | def isoFile = "config-drive/cloudata.iso" |
| 179 | if (fileExists(isoFile)) { |
| 180 | sh "rm -v ${isoFile}" |
| 181 | } |
| 182 | // This is left for backward-compatibility |
| 183 | if (fileExists("config-drive/user-data.yaml")) { |
| 184 | sh "mv config-drive/user-data.yaml config-drive/user-data" |
| 185 | if (!fileExists("config-drive/meta-data")) { |
| 186 | sh "echo 'hostname: ubuntu' > config-drive/meta-data" |
| 187 | } |
| 188 | } |
| 189 | sh "mkisofs -o ${isoFile} -V cidata -r -J --quiet config-drive" |
| 190 | archiveArtifacts artifacts: "${isoFile}" |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (job_env.BUILD_ONLY == "openstack") { |
| 195 | dir("${workspace}/${job_env.BUILD_OS}/") { |
| 196 | extra_vars_list = MapToList(extra_vars) |
| 197 | withEnv(["PATH=${env.PATH}:${workspace}/bin", |
| 198 | "PACKER_LOG_PATH=${_packer_log}", |
| 199 | "PACKER_LOG=1", |
| 200 | "TMPDIR=${workspace}/tmp", |
| 201 | "OS_USERNAME=${creds.username.toString()}", |
| 202 | "OS_PASSWORD=${creds.password.toString()}"] + extra_vars_list) { |
| 203 | |
| 204 | common.infoMsg("Run build with:") |
| 205 | sh(script: 'printenv|sort') |
| 206 | sh(script: "set -xe; packer build -only='openstack' ${_packer_args} -parallel=false template.json") |
| 207 | _os_private = "${workspace}/${job_env.BUILD_OS}/os_${job_env.BUILD_OS}.pem" |
| 208 | if (fileExists(_os_private)) { |
| 209 | common.infoMsg("Packer private key:") |
| 210 | sh "cat ${_os_private}" |
| 211 | } |
| 212 | def packerStatus = sh(script: "grep \"Some builds didn't complete successfully and had errors\" ${_packer_log}", returnStatus: true) |
| 213 | // grep returns 0 if find something |
| 214 | if (packerStatus != 0) { |
| 215 | common.infoMsg("Openstack instance build complete") |
| 216 | } else { |
| 217 | throw new Exception("Openstack Packer build failed") |
| 218 | } |
| 219 | |
| 220 | common.retry(3, 5) { |
| 221 | common.infoMsg("Attempt download openstack image..") |
| 222 | openstack.runOpenstackCommand("openstack image save --file ${_artifact_dir}/${imageName}.qcow2 ${imageName}", rcFile, openstackEnv) |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | } else if (job_env.BUILD_ONLY == 'qemu') { |
| 228 | |
| 229 | dir("${workspace}/${job_env.BUILD_OS}/") { |
| 230 | extra_vars_list = MapToList(extra_vars) |
| 231 | withEnv(["PATH=${env.PATH}:${workspace}/bin", |
| 232 | "PACKER_LOG_PATH=${_packer_log}", |
| 233 | "PACKER_LOG=1", |
| 234 | "TMPDIR=${workspace}/tmp", |
| 235 | "PACKER_IMAGES_CACHE=${ImagesCacheFolder}"] + extra_vars_list) { |
| 236 | common.infoMsg("Run build with:") |
| 237 | sh(script: 'printenv|sort') |
| 238 | sh(script: "set -xe ; packer build -on-error=ask -only='qemu' ${_packer_args} -parallel=false template.json".toString()) |
| 239 | |
| 240 | def packerStatus = sh(script: "grep \"Some builds didn't complete successfully and had errors\" ${PACKER_LOG_PATH}", returnStatus: true) |
| 241 | // grep returns 0 if find something |
| 242 | if (packerStatus != 0) { |
| 243 | common.infoMsg("qemu instance build completed successfully") |
| 244 | } else { |
| 245 | throw new Exception("qemu instance build failed") |
| 246 | } |
| 247 | // collect artifacts |
| 248 | // TODO make it possible, process multiply artifacts by one run. |
| 249 | dir('images/') { |
Aleksey Zvyagintsev | 42e7695 | 2018-12-14 13:40:44 +0000 | [diff] [blame] | 250 | sh(script: 'find .') |
| 251 | def _files = findFiles(glob: "*qemu*/*${imageName}*.qcow2") |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 252 | if (_files.size() > 1) { |
| 253 | common.warningMsg("Multiply artifacts detected!Only first one will be processed!") |
| 254 | } else if (_files.size() == 0) { |
| 255 | throw new Exception("No artifacts detected!BUILD_ONLY=${env.BUILD_ONLY} failed!") |
| 256 | } |
| 257 | for (String x : _files) { |
| 258 | _file = sh(script: "set -x ; readlink -f ${x}", returnStdout: true) |
| 259 | sh(script: "mv -v ${x} ${_artifact_dir}/${imageName}.qcow2") |
| 260 | // Save filename to list |
| 261 | _artifact_list.add("${imageName}.qcow2") |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | } else { |
| 268 | throw new Exception("Unexpected BUILD_ONLY=${env.BUILD_ONLY} target!") |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | stage("Publish artifacts") { |
| 273 | dir(_artifact_dir) { |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 274 | def published = false |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 275 | common.infoMsg("Processing md5 for artifacts") |
| 276 | for (String x : _artifact_list) { |
| 277 | _md5 = sh(script: "md5sum ${x} > ${x}.md5; cat ${x}.md5", returnStdout: true).trim() |
| 278 | _size = sh(script: "ls -alh ${x}", returnStdout: true).trim() |
| 279 | common.infoMsg("Artifact file: ${_size}\n${_md5}") |
| 280 | } |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 281 | if ('local' in publishBackends) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 282 | common.infoMsg("Uploading to: local") |
| 283 | common.infoMsg("For local publish target - nothing to do, all files in: ${_artifact_dir}") |
| 284 | if (job_env.get('CLEANUP_AFTER', false)) { |
| 285 | common.warningMsg("You are trying to use 'local' publish method, along with enabled CLEANUP_AFTER! ") |
| 286 | common.warningMsg("Disabling CLEANUP_AFTER option, to save you'r data ;) ") |
| 287 | job_env.CLEANUP_AFTER = false |
| 288 | } |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 289 | published = true |
| 290 | } |
| 291 | if ('glance' in publishBackends) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 292 | common.infoMsg("Uploading to: glance-openstack") |
| 293 | if (fileExists("${workspace}/venv")) { |
| 294 | common.infoMsg("cleaning virtualenv at:${workspace}/venv") |
| 295 | sh(script: "rm -rf ${workspace}/venv", returnStatus: true) |
| 296 | } |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 297 | openstack.setupOpenstackVirtualenv(openstackEnv) |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 298 | for (String x : findFiles(glob: "*.*")) { |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 299 | if (x.getName().endsWith('.qcow2')) { |
| 300 | _md5sum = sh(script: "cat ${x}.md5", returnStdout: true).trim().split()[0] |
Denis Egorenko | f4acb4a | 2019-01-26 13:58:58 +0400 | [diff] [blame] | 301 | _property = "--property data=${dateTime} --property md5sum=${_md5sum} --property build='${env.BUILD_URL}' --container-format bare --disk-format qcow2" |
Denis Egorenko | bae3501 | 2019-03-04 12:56:42 +0400 | [diff] [blame^] | 302 | _cmdline = String.format("glance image-create %s --name '%s' --file %s", _property, imageName, x) |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 303 | openstack.runOpenstackCommand(_cmdline, rcFile, openstackEnv) |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 304 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 305 | } |
Denis Egorenko | c6dde3a | 2019-01-30 15:54:16 +0400 | [diff] [blame] | 306 | currentBuild.description = "${imageName}.qcow2 uploaded tenant: ${os_openrc['OS_PROJECT_NAME']}" |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 307 | published = true |
| 308 | } |
| 309 | if ('http' in publishBackends) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 310 | for (String u_file : findFiles(glob: '*.*')) { |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 311 | common.infoMsg("Uploading image ${u_file}") |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 312 | def uploadImageStatus = '' |
| 313 | common.retry(3, 5) { |
| 314 | uploadImageStatus = sh(script: "curl -f -T ${u_file} ${job_env.UPLOAD_URL}", returnStatus: true) |
| 315 | if (uploadImageStatus != 0) { |
| 316 | throw new Exception("Uploading file: ${u_file} failed!") |
| 317 | } |
| 318 | } |
| 319 | // Fixme for correct path ? |
| 320 | currentBuild.description = "<a href='http://images.mcp.mirantis.net/${imageName}.qcow2'>${imageName}.qcow2</a>" |
| 321 | } |
Denis Egorenko | c0aba19 | 2019-01-23 18:03:53 +0400 | [diff] [blame] | 322 | published = true |
| 323 | } |
| 324 | if (! published) { |
| 325 | throw new Exception("Unsupported publish backend: ${publishBackends}") |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | } |
| 329 | } |
| 330 | } catch (Throwable e) { |
| 331 | // If there was an error or exception thrown, the build failed |
| 332 | currentBuild.result = "FAILURE" |
| 333 | throw e |
| 334 | } finally { |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 335 | if (job_env.get('CLEANUP_AFTER', false)) { |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 336 | dir(workspace) { |
| 337 | sh "find . -mindepth 1 -delete || true" |
azvyagintsev | f2c70cc | 2018-07-12 12:19:11 +0300 | [diff] [blame] | 338 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 339 | if (job_env.BUILD_ONLY == 'openstack') { |
| 340 | common.warningMsg("openstack Env cleanup not implemented yet!") |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 341 | } |
Ivan Berezovskiy | 23035a2 | 2018-11-14 13:25:51 +0400 | [diff] [blame] | 342 | } else { |
| 343 | common.warningMsg("Env has not been cleaned!Please cleanup it manualy!") |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 344 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 345 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 346 | } |
azvyagintsev | 68786a1 | 2018-07-10 14:42:29 +0300 | [diff] [blame] | 347 | } |