blob: 59dd3eb46d6c31eef5e9341235a3cb93525eb416 [file] [log] [blame]
Jakub Josef42e568c2018-01-24 13:18:23 +01001/**
Jakub Josef5edceb92018-02-05 17:10:33 +01002 * Pipeline for generating sphinx reclass generated documentation
Jakub Josef3d72fa62018-01-24 14:12:53 +01003 * MODEL_GIT_URL
4 * MODEL_GIT_REF
5 * CLUSTER_NAME
Jakub Josef42e568c2018-01-24 13:18:23 +01006 *
7 */
8
Jakub Josef42e568c2018-01-24 13:18:23 +01009common = new com.mirantis.mk.Common()
Jakub Josef3d72fa62018-01-24 14:12:53 +010010ssh = new com.mirantis.mk.Ssh()
Jakub Josef42e568c2018-01-24 13:18:23 +010011gerrit = new com.mirantis.mk.Gerrit()
Jakub Josef3d72fa62018-01-24 14:12:53 +010012git = new com.mirantis.mk.Git()
Jakub Josef42e568c2018-01-24 13:18:23 +010013python = new com.mirantis.mk.Python()
14salt = new com.mirantis.mk.Salt()
15
16timeout(time: 12, unit: 'HOURS') {
azvyagintsev636493c2018-09-12 17:17:05 +030017 node("python") {
18 try {
19 def workspace = common.getWorkspace()
20 def masterName = "cfg01." + CLUSTER_NAME.replace("-", "_") + ".lab"
21 def jenkinsUserIds = common.getJenkinsUserIds()
22 def img = docker.image("tcpcloud/salt-models-testing:nightly")
23 img.pull()
24 img.inside("-u root:root --hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") {
25 stage("Prepare salt env") {
26 if (MODEL_GIT_REF != "" && MODEL_GIT_URL != "") {
27 checkouted = gerrit.gerritPatchsetCheckout(MODEL_GIT_URL, MODEL_GIT_REF, "HEAD", CREDENTIALS_ID)
28 } else {
29 throw new Exception("Cannot checkout gerrit patchset, MODEL_GIT_URL or MODEL_GIT_REF is null")
Jakub Josef3d72fa62018-01-24 14:12:53 +010030 }
azvyagintsev636493c2018-09-12 17:17:05 +030031 if (checkouted) {
32 if (fileExists('classes/system')) {
33 ssh.prepareSshAgentKey(CREDENTIALS_ID)
34 dir('classes/system') {
35 // XXX: JENKINS-33510 dir step not work properly inside containers, so let's taky reclass system model directly
36 //remoteUrl = git.getGitRemote()
37 ssh.ensureKnownHosts("https://github.com/Mirantis/reclass-system-salt-model")
38 }
39 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
40 }
41 }
42 withEnv(["MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${CLUSTER_NAME}", "MINION_ID=${masterName}"]) {
43 sh("cp -r ${workspace}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts")
44 sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \
Jakub Josef42e568c2018-01-24 13:18:23 +010045 && source_local_envs \
46 && configure_salt_master \
47 && configure_salt_minion \
48 && install_salt_formula_pkg; \
49 saltservice_restart; \
50 saltmaster_init'""")
azvyagintsev636493c2018-09-12 17:17:05 +030051 }
Jakub Josef3d72fa62018-01-24 14:12:53 +010052 }
azvyagintsev636493c2018-09-12 17:17:05 +030053 stage("Generate documentation") {
54 def saltResult = sh(script: "salt-call state.sls salt.minion,sphinx.server,nginx", returnStatus: true)
55 if (saltResult > 0) {
56 common.warnMsg("Salt call salt.minion,sphinx.server,nginx failed but continuing")
57 }
58 }
59 stage("Publish outputs") {
60 try {
61 // /srv/static/sites/reclass_doc will be used for publishHTML step
62 // /srv/static/extern will be used as tar artifact
63 def outputPresent = sh(script: "ls /srv/static/sites/reclass_doc > /dev/null 2>&1 && ls /srv/static/extern > /dev/null 2>&1", returnStatus: true) == 0
64 if (outputPresent) {
65 sh("""mkdir ${workspace}/output && \
Jakub Josef5edceb92018-02-05 17:10:33 +010066 tar -zcf ${workspace}/output/docs-html.tar.gz /srv/static/sites/reclass_doc && \
67 tar -zcf ${workspace}/output/docs-src.tar.gz /srv/static/extern && \
68 cp -R /srv/static/sites/reclass_doc ${workspace}/output && \
69 chown -R ${jenkinsUserIds[0]}:${jenkinsUserIds[1]} ${workspace}/output""")
70
azvyagintsev636493c2018-09-12 17:17:05 +030071 publishHTML(target: [
72 alwaysLinkToLastBuild: true,
73 keepAll : true,
74 reportDir : 'output/reclass_doc',
75 reportFiles : 'index.html',
76 reportName : "Reclass-documentation"
77 ])
78 archiveArtifacts artifacts: "output/*"
79 } else {
80 common.errorMsg("Documentation publish failed, one of output directories /srv/static/sites/reclass_doc or /srv/static/extern not exists!")
81 }
82 } catch (Exception e) {
83 common.errorMsg("Documentation publish stage failed!")
84 }
Jakub Josef22815b02018-01-30 16:05:26 +010085 }
azvyagintsev636493c2018-09-12 17:17:05 +030086 }
87 } catch (Throwable e) {
88 // If there was an error or exception thrown, the build failed
89 currentBuild.result = "FAILURE"
90 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
91 throw e
92 } finally {
93 common.sendNotification(currentBuild.result, "", ["slack"])
94 }
Jakub Josef42e568c2018-01-24 13:18:23 +010095 }
Jakub Josef42e568c2018-01-24 13:18:23 +010096}