Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Generate cookiecutter cluster by individual products |
| 3 | * |
| 4 | * Expected parameters: |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 5 | * COOKIECUTTER_TEMPLATE_CONTEXT Context parameters for the template generation. |
Tomáš Kukrál | 91e4925 | 2017-05-09 14:40:26 +0200 | [diff] [blame] | 6 | * EMAIL_ADDRESS Email to send a created tar file |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 7 | * |
azvyagintsev | 3ed704f | 2018-07-09 15:49:27 +0300 | [diff] [blame] | 8 | **/ |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 9 | |
| 10 | common = new com.mirantis.mk.Common() |
| 11 | git = new com.mirantis.mk.Git() |
| 12 | python = new com.mirantis.mk.Python() |
chnyda | 8919101 | 2017-05-29 15:38:35 +0200 | [diff] [blame] | 13 | saltModelTesting = new com.mirantis.mk.SaltModelTesting() |
Tomáš Kukrál | cebc1a0 | 2017-07-25 16:10:37 +0200 | [diff] [blame] | 14 | ssh = new com.mirantis.mk.Ssh() |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 15 | |
azvyagintsev | b8ddb49 | 2018-09-12 14:59:45 +0300 | [diff] [blame] | 16 | slaveNode = env.SLAVE_NODE ?: 'python&&docker' |
azvyagintsev | f252b59 | 2018-08-13 18:39:14 +0300 | [diff] [blame] | 17 | |
| 18 | timeout(time: 2, unit: 'HOURS') { |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 19 | node(slaveNode) { |
| 20 | def templateEnv = "${env.WORKSPACE}/template" |
| 21 | def modelEnv = "${env.WORKSPACE}/model" |
| 22 | def testEnv = "${env.WORKSPACE}/test" |
| 23 | def pipelineEnv = "${env.WORKSPACE}/pipelines" |
Tomáš Kukrál | 9f6260f | 2017-03-29 23:58:26 +0200 | [diff] [blame] | 24 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 25 | try { |
| 26 | def templateContext = readYaml text: COOKIECUTTER_TEMPLATE_CONTEXT |
| 27 | def mcpVersion = templateContext.default_context.mcp_version |
| 28 | def sharedReclassUrl = templateContext.default_context.shared_reclass_url |
| 29 | def clusterDomain = templateContext.default_context.cluster_domain |
| 30 | def clusterName = templateContext.default_context.cluster_name |
| 31 | def saltMaster = templateContext.default_context.salt_master_hostname |
| 32 | def localRepositories = templateContext.default_context.local_repositories.toBoolean() |
| 33 | def offlineDeployment = templateContext.default_context.offline_deployment.toBoolean() |
| 34 | def cutterEnv = "${env.WORKSPACE}/cutter" |
| 35 | def jinjaEnv = "${env.WORKSPACE}/jinja" |
| 36 | def outputDestination = "${modelEnv}/classes/cluster/${clusterName}" |
| 37 | def systemEnv = "${modelEnv}/classes/system" |
| 38 | def targetBranch = "feature/${clusterName}" |
| 39 | def templateBaseDir = "${env.WORKSPACE}/template" |
| 40 | def templateDir = "${templateEnv}/template/dir" |
| 41 | def templateOutputDir = templateBaseDir |
| 42 | def user |
| 43 | def testResult = false |
| 44 | wrap([$class: 'BuildUser']) { |
| 45 | user = env.BUILD_USER_ID |
Tomáš Kukrál | a3f4ba7 | 2017-08-03 15:40:22 +0200 | [diff] [blame] | 46 | } |
| 47 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 48 | currentBuild.description = clusterName |
| 49 | print("Using context:\n" + COOKIECUTTER_TEMPLATE_CONTEXT) |
Richard Felkl | e77b091 | 2018-01-31 17:12:23 +0100 | [diff] [blame] | 50 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 51 | stage('Download Cookiecutter template') { |
| 52 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 53 | def cookiecutterTemplateUrl = templateContext.default_context.cookiecutter_template_url |
| 54 | def cookiecutterTemplateBranch = templateContext.default_context.cookiecutter_template_branch |
| 55 | git.checkoutGitRepository(templateEnv, cookiecutterTemplateUrl, 'master') |
| 56 | // Use refspec if exists first of all |
| 57 | if (cookiecutterTemplateBranch.toString().startsWith('refs/')) { |
| 58 | dir(templateEnv) { |
| 59 | ssh.agentSh("git fetch ${cookiecutterTemplateUrl} ${cookiecutterTemplateBranch} && git checkout FETCH_HEAD") |
| 60 | } |
| 61 | } else { |
| 62 | // Use mcpVersion git tag if not specified branch for cookiecutter-templates |
| 63 | if (cookiecutterTemplateBranch == '') { |
| 64 | cookiecutterTemplateBranch = mcpVersion |
| 65 | // Don't have nightly/testing/stable for cookiecutter-templates repo, therefore use master |
| 66 | if (["nightly", "testing", "stable"].contains(mcpVersion)) { |
| 67 | cookiecutterTemplateBranch = 'master' |
| 68 | } |
| 69 | } |
| 70 | git.changeGitBranch(templateEnv, cookiecutterTemplateBranch) |
| 71 | } |
| 72 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 73 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 74 | stage('Create empty reclass model') { |
| 75 | dir(path: modelEnv) { |
| 76 | sh "rm -rfv .git" |
| 77 | sh "git init" |
| 78 | ssh.agentSh("git submodule add ${sharedReclassUrl} 'classes/system'") |
| 79 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 80 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 81 | def sharedReclassBranch = templateContext.default_context.shared_reclass_branch |
| 82 | // Use refspec if exists first of all |
| 83 | if (sharedReclassBranch.toString().startsWith('refs/')) { |
| 84 | dir(systemEnv) { |
| 85 | ssh.agentSh("git fetch ${sharedReclassUrl} ${sharedReclassBranch} && git checkout FETCH_HEAD") |
| 86 | } |
| 87 | } else { |
| 88 | // Use mcpVersion git tag if not specified branch for reclass-system |
| 89 | if (sharedReclassBranch == '') { |
| 90 | sharedReclassBranch = mcpVersion |
| 91 | // Don't have nightly/testing for reclass-system repo, therefore use master |
| 92 | if (["nightly", "testing", "stable"].contains(mcpVersion)) { |
| 93 | common.warningMsg("Fetching reclass-system from master!") |
| 94 | sharedReclassBranch = 'master' |
| 95 | } |
| 96 | } |
| 97 | git.changeGitBranch(systemEnv, sharedReclassBranch) |
| 98 | } |
| 99 | git.commitGitChanges(modelEnv, "Added new shared reclass submodule", "${user}@localhost", "${user}") |
| 100 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 102 | def productList = ["infra", "cicd", "opencontrail", "kubernetes", "openstack", "oss", "stacklight", "ceph"] |
| 103 | for (product in productList) { |
Richard Felkl | 9543faa | 2018-01-11 09:47:35 +0100 | [diff] [blame] | 104 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 105 | // get templateOutputDir and productDir |
Michal Kobus | 197f611 | 2018-09-21 14:30:16 +0200 | [diff] [blame] | 106 | templateOutputDir = "${env.WORKSPACE}/output/${product}" |
| 107 | productDir = product |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 108 | templateDir = "${templateEnv}/cluster_product/${productDir}" |
| 109 | // Bw for 2018.8.1 and older releases |
| 110 | if (product.startsWith("stacklight") && (!fileExists(templateDir))) { |
| 111 | common.warningMsg("Old release detected! productDir => 'stacklight2' ") |
| 112 | productDir = "stacklight2" |
azvyagintsev | 458278c | 2018-09-25 18:38:30 +0300 | [diff] [blame] | 113 | templateDir = "${templateEnv}/cluster_product/${productDir}" |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 114 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 115 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 116 | if (product == "infra" || (templateContext.default_context["${product}_enabled"] |
| 117 | && templateContext.default_context["${product}_enabled"].toBoolean())) { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 118 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 119 | common.infoMsg("Generating product " + product + " from " + templateDir + " to " + templateOutputDir) |
| 120 | |
| 121 | sh "rm -rf ${templateOutputDir} || true" |
| 122 | sh "mkdir -p ${templateOutputDir}" |
| 123 | sh "mkdir -p ${outputDestination}" |
| 124 | |
| 125 | python.setupCookiecutterVirtualenv(cutterEnv) |
| 126 | python.buildCookiecutterTemplate(templateDir, COOKIECUTTER_TEMPLATE_CONTEXT, templateOutputDir, cutterEnv, templateBaseDir) |
| 127 | sh "mv -v ${templateOutputDir}/${clusterName}/* ${outputDestination}" |
| 128 | } else { |
| 129 | common.warningMsg("Product " + product + " is disabled") |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (localRepositories && !offlineDeployment) { |
| 134 | def aptlyModelUrl = templateContext.default_context.local_model_url |
| 135 | dir(path: modelEnv) { |
| 136 | ssh.agentSh "git submodule add \"${aptlyModelUrl}\" \"classes/cluster/${clusterName}/cicd/aptly\"" |
| 137 | if (!(mcpVersion in ["nightly", "testing", "stable"])) { |
| 138 | ssh.agentSh "cd \"classes/cluster/${clusterName}/cicd/aptly\";git fetch --tags;git checkout ${mcpVersion}" |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | stage('Generate new SaltMaster node') { |
| 144 | def nodeFile = "${modelEnv}/nodes/${saltMaster}.${clusterDomain}.yml" |
| 145 | def nodeString = """classes: |
Leontii Istomin | 56b6b11 | 2018-01-15 12:14:24 +0300 | [diff] [blame] | 146 | - cluster.${clusterName}.infra.config |
| 147 | parameters: |
| 148 | _param: |
| 149 | linux_system_codename: xenial |
| 150 | reclass_data_revision: master |
| 151 | linux: |
| 152 | system: |
| 153 | name: ${saltMaster} |
| 154 | domain: ${clusterDomain} |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 155 | """ |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 156 | sh "mkdir -p ${modelEnv}/nodes/" |
| 157 | writeFile(file: nodeFile, text: nodeString) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 158 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 159 | git.commitGitChanges(modelEnv, "Create model ${clusterName}", "${user}@localhost", "${user}") |
| 160 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 161 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 162 | stage("Test") { |
| 163 | if (TEST_MODEL.toBoolean() && sharedReclassUrl != '') { |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 164 | distribRevision = mcpVersion |
| 165 | if (['master'].contains(mcpVersion)) { |
| 166 | distribRevision = 'nightly' |
| 167 | } |
| 168 | if (distribRevision.contains('/')) { |
| 169 | distribRevision = distribRevision.split('/')[-1] |
| 170 | } |
| 171 | // Check if we are going to test bleeding-edge release, which doesn't have binary release yet |
| 172 | if (!common.checkRemoteBinary([apt_mk_version: distribRevision]).linux_system_repo_url) { |
| 173 | common.errorMsg("Binary release: ${distribRevision} not exist. Fallback to 'proposed'! ") |
| 174 | distribRevision = 'proposed' |
| 175 | } |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 176 | sh("cp -r ${modelEnv} ${testEnv}") |
| 177 | def DockerCName = "${env.JOB_NAME.toLowerCase()}_${env.BUILD_TAG.toLowerCase()}" |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 178 | common.infoMsg("Attempt to run test against distribRevision: ${distribRevision}") |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 179 | try { |
| 180 | def config = [ |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 181 | 'dockerHostname' : "${saltMaster}.${clusterDomain}", |
| 182 | 'reclassEnv' : testEnv, |
azvyagintsev | 1bcadc4 | 2018-10-05 20:13:15 +0300 | [diff] [blame] | 183 | 'distribRevision' : distribRevision, |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 184 | 'dockerContainerName': DockerCName, |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 185 | 'testContext' : 'salt-model-node' |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 186 | ] |
| 187 | testResult = saltModelTesting.testNode(config) |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 188 | common.infoMsg("Test finished: SUCCESS") |
Denis Egorenko | 032b8ca | 2018-09-13 17:00:23 +0400 | [diff] [blame] | 189 | } catch (Exception ex) { |
| 190 | common.warningMsg("Test finished: FAILED") |
| 191 | testResult = false |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 192 | } |
| 193 | } else { |
| 194 | common.warningMsg("Test stage has been skipped!") |
| 195 | } |
| 196 | } |
| 197 | stage("Generate config drives") { |
| 198 | // apt package genisoimage is required for this stage |
| 199 | |
| 200 | // download create-config-drive |
| 201 | // FIXME: that should be refactored, to use git clone - to be able download it from custom repo. |
Ivan Berezovskiy | 95ec927 | 2018-09-18 16:41:18 +0400 | [diff] [blame] | 202 | def mcpCommonScriptsBranch = templateContext['default_context']['mcp_common_scripts_branch'] |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 203 | if (mcpCommonScriptsBranch == '') { |
| 204 | mcpCommonScriptsBranch = mcpVersion |
| 205 | // Don't have n/t/s for mcp-common-scripts repo, therefore use master |
| 206 | if (["nightly", "testing", "stable"].contains(mcpVersion)) { |
| 207 | common.warningMsg("Fetching mcp-common-scripts from master!") |
| 208 | mcpCommonScriptsBranch = 'master' |
| 209 | } |
| 210 | } |
Ivan Berezovskiy | 95ec927 | 2018-09-18 16:41:18 +0400 | [diff] [blame] | 211 | |
Roman Vyalov | f0c596e | 2018-10-01 17:56:09 +0300 | [diff] [blame] | 212 | def commonScriptsRepoUrl = 'https://gerrit.mcp.mirantis.com/mcp/mcp-common-scripts' |
Ivan Berezovskiy | 95ec927 | 2018-09-18 16:41:18 +0400 | [diff] [blame] | 213 | checkout([ |
azvyagintsev | 7cdcc7a | 2018-09-25 16:47:24 +0300 | [diff] [blame] | 214 | $class : 'GitSCM', |
| 215 | branches : [[name: 'FETCH_HEAD'],], |
| 216 | extensions : [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'mcp-common-scripts']], |
| 217 | userRemoteConfigs: [[url: commonScriptsRepoUrl, refspec: mcpCommonScriptsBranch],], |
Ivan Berezovskiy | 95ec927 | 2018-09-18 16:41:18 +0400 | [diff] [blame] | 218 | ]) |
| 219 | |
| 220 | sh "cp mcp-common-scripts/config-drive/create_config_drive.sh create-config-drive && chmod +x create-config-drive" |
Ivan Berezovskiy | 3379c7a | 2018-09-14 19:02:46 +0400 | [diff] [blame] | 221 | sh "[ -f mcp-common-scripts/config-drive/master_config.sh ] && cp mcp-common-scripts/config-drive/master_config.sh user_data || cp mcp-common-scripts/config-drive/master_config.yaml user_data" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 222 | |
| 223 | sh "git clone --mirror https://github.com/Mirantis/mk-pipelines.git ${pipelineEnv}/mk-pipelines" |
| 224 | sh "git clone --mirror https://github.com/Mirantis/pipeline-library.git ${pipelineEnv}/pipeline-library" |
Ivan Berezovskiy | 3379c7a | 2018-09-14 19:02:46 +0400 | [diff] [blame] | 225 | args = "--user-data user_data --hostname ${saltMaster} --model ${modelEnv} --mk-pipelines ${pipelineEnv}/mk-pipelines/ --pipeline-library ${pipelineEnv}/pipeline-library/ ${saltMaster}.${clusterDomain}-config.iso" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 226 | |
| 227 | // load data from model |
| 228 | def smc = [:] |
| 229 | smc['SALT_MASTER_MINION_ID'] = "${saltMaster}.${clusterDomain}" |
| 230 | smc['SALT_MASTER_DEPLOY_IP'] = templateContext['default_context']['salt_master_management_address'] |
| 231 | smc['DEPLOY_NETWORK_GW'] = templateContext['default_context']['deploy_network_gateway'] |
| 232 | smc['DEPLOY_NETWORK_NETMASK'] = templateContext['default_context']['deploy_network_netmask'] |
| 233 | if (templateContext['default_context'].get('deploy_network_mtu')) { |
| 234 | smc['DEPLOY_NETWORK_MTU'] = templateContext['default_context']['deploy_network_mtu'] |
| 235 | } |
| 236 | smc['DNS_SERVERS'] = templateContext['default_context']['dns_server01'] |
| 237 | smc['MCP_VERSION'] = "${mcpVersion}" |
| 238 | if (templateContext['default_context']['local_repositories'] == 'True') { |
| 239 | def localRepoIP = templateContext['default_context']['local_repo_url'] |
| 240 | smc['MCP_SALT_REPO_KEY'] = "http://${localRepoIP}/public.gpg" |
| 241 | smc['MCP_SALT_REPO_URL'] = "http://${localRepoIP}/ubuntu-xenial" |
| 242 | smc['PIPELINES_FROM_ISO'] = 'false' |
| 243 | smc['PIPELINE_REPO_URL'] = "http://${localRepoIP}:8088" |
| 244 | smc['LOCAL_REPOS'] = 'true' |
| 245 | } |
| 246 | if (templateContext['default_context']['upstream_proxy_enabled'] == 'True') { |
| 247 | if (templateContext['default_context']['upstream_proxy_auth_enabled'] == 'True') { |
| 248 | smc['http_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_user'] + ':' + templateContext['default_context']['upstream_proxy_password'] + '@' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 249 | smc['https_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_user'] + ':' + templateContext['default_context']['upstream_proxy_password'] + '@' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 250 | } else { |
| 251 | smc['http_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 252 | smc['https_proxy'] = 'http://' + templateContext['default_context']['upstream_proxy_address'] + ':' + templateContext['default_context']['upstream_proxy_port'] |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | for (i in common.entries(smc)) { |
Ivan Berezovskiy | 3379c7a | 2018-09-14 19:02:46 +0400 | [diff] [blame] | 257 | sh "sed -i 's,${i[0]}=.*,${i[0]}=${i[1]},' user_data" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // create cfg config-drive |
| 261 | sh "./create-config-drive ${args}" |
| 262 | sh("mkdir output-${clusterName} && mv ${saltMaster}.${clusterDomain}-config.iso output-${clusterName}/") |
| 263 | |
| 264 | // save cfg iso to artifacts |
| 265 | archiveArtifacts artifacts: "output-${clusterName}/${saltMaster}.${clusterDomain}-config.iso" |
| 266 | |
| 267 | if (templateContext['default_context']['local_repositories'] == 'True') { |
| 268 | def aptlyServerHostname = templateContext.default_context.aptly_server_hostname |
Ivan Berezovskiy | ffff330 | 2018-09-21 19:02:39 +0400 | [diff] [blame] | 269 | sh "[ -f mcp-common-scripts/config-drive/mirror_config.yaml ] && cp mcp-common-scripts/config-drive/mirror_config.yaml mirror_config || cp mcp-common-scripts/config-drive/mirror_config.sh mirror_config" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 270 | |
| 271 | def smc_apt = [:] |
| 272 | smc_apt['SALT_MASTER_DEPLOY_IP'] = templateContext['default_context']['salt_master_management_address'] |
| 273 | smc_apt['APTLY_DEPLOY_IP'] = templateContext['default_context']['aptly_server_deploy_address'] |
| 274 | smc_apt['APTLY_DEPLOY_NETMASK'] = templateContext['default_context']['deploy_network_netmask'] |
| 275 | smc_apt['APTLY_MINION_ID'] = "${aptlyServerHostname}.${clusterDomain}" |
| 276 | |
| 277 | for (i in common.entries(smc_apt)) { |
Ivan Berezovskiy | ffff330 | 2018-09-21 19:02:39 +0400 | [diff] [blame] | 278 | sh "sed -i \"s,export ${i[0]}=.*,export ${i[0]}=${i[1]},\" mirror_config" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // create apt config-drive |
Ivan Berezovskiy | ffff330 | 2018-09-21 19:02:39 +0400 | [diff] [blame] | 282 | sh "./create-config-drive --user-data mirror_config --hostname ${aptlyServerHostname} ${aptlyServerHostname}.${clusterDomain}-config.iso" |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 283 | sh("mv ${aptlyServerHostname}.${clusterDomain}-config.iso output-${clusterName}/") |
| 284 | |
| 285 | // save apt iso to artifacts |
| 286 | archiveArtifacts artifacts: "output-${clusterName}/${aptlyServerHostname}.${clusterDomain}-config.iso" |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | stage('Save changes reclass model') { |
| 291 | sh(returnStatus: true, script: "tar -czf output-${clusterName}/${clusterName}.tar.gz --exclude='*@tmp' -C ${modelEnv} .") |
| 292 | archiveArtifacts artifacts: "output-${clusterName}/${clusterName}.tar.gz" |
| 293 | |
azvyagintsev | 636493c | 2018-09-12 17:17:05 +0300 | [diff] [blame] | 294 | if (EMAIL_ADDRESS != null && EMAIL_ADDRESS != "") { |
| 295 | emailext(to: EMAIL_ADDRESS, |
| 296 | attachmentsPattern: "output-${clusterName}/*", |
| 297 | body: "Mirantis Jenkins\n\nRequested reclass model ${clusterName} has been created and attached to this email.\nEnjoy!\n\nMirantis", |
| 298 | subject: "Your Salt model ${clusterName}") |
| 299 | } |
| 300 | dir("output-${clusterName}") { |
| 301 | deleteDir() |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | // Fail, but leave possibility to get failed artifacts |
| 306 | if (!testResult && TEST_MODEL.toBoolean()) { |
| 307 | common.warningMsg('Test finished: FAILURE. Please check logs and\\or debug failed model manually!') |
| 308 | error('Test stage finished: FAILURE') |
| 309 | } |
| 310 | |
| 311 | } catch (Throwable e) { |
| 312 | currentBuild.result = "FAILURE" |
| 313 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 314 | throw e |
| 315 | } finally { |
| 316 | stage('Clean workspace directories') { |
| 317 | sh(script: 'find . -mindepth 1 -delete > /dev/null || true') |
| 318 | } |
| 319 | // common.sendNotification(currentBuild.result,"",["slack"]) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 320 | } |
Tomáš Kukrál | 7ded364 | 2017-03-27 15:52:51 +0200 | [diff] [blame] | 321 | } |
Mikhail Ivanov | 9f81292 | 2017-11-07 18:52:02 +0400 | [diff] [blame] | 322 | } |