blob: 4a36f0e34ce826111326d9abac1ac1d8b89c834d [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') {
17 node("python") {
18 try {
Jakub Josef3d72fa62018-01-24 14:12:53 +010019 def workspace = common.getWorkspace()
20 def masterName = "cfg01." + CLUSTER_NAME.replace("-","_") + ".lab"
Jakub Josef5edceb92018-02-05 17:10:33 +010021 def jenkinsUserIds = common.getJenkinsUserIds()
Jakub Josef3d72fa62018-01-24 14:12:53 +010022 def img = docker.image("tcpcloud/salt-models-testing:nightly")
Jakub Josef42e568c2018-01-24 13:18:23 +010023 img.pull()
Jakub Josefad56efe2018-02-01 13:56:44 +010024 img.inside("-u root:root --hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") {
Jakub Josef42e568c2018-01-24 13:18:23 +010025 stage("Prepare salt env") {
Jakub Josef3d72fa62018-01-24 14:12:53 +010026 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")
30 }
31 if(checkouted) {
32 if (fileExists('classes/system')) {
33 ssh.prepareSshAgentKey(CREDENTIALS_ID)
34 dir('classes/system') {
Jakub Josef5edceb92018-02-05 17:10:33 +010035 // XXX: JENKINS-33510 dir step not work properly inside containers, so let's taky reclass system model directly
Jakub Josef3d72fa62018-01-24 14:12:53 +010036 //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 }
Jakub Josef3d72fa62018-01-24 14:12:53 +010042 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")
Jakub Josef42e568c2018-01-24 13:18:23 +010044 sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \
45 && source_local_envs \
46 && configure_salt_master \
47 && configure_salt_minion \
48 && install_salt_formula_pkg; \
49 saltservice_restart; \
50 saltmaster_init'""")
51 }
52 }
Jakub Josef42e568c2018-01-24 13:18:23 +010053 stage("Generate documentation"){
Jakub Josef3d72fa62018-01-24 14:12:53 +010054 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"){
Jakub Josef5edceb92018-02-05 17:10:33 +010060 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 && \
66 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
71 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) {
Jakub Josef22815b02018-01-30 16:05:26 +010083 common.errorMsg("Documentation publish stage failed!")
Jakub Josef22815b02018-01-30 16:05:26 +010084 }
Jakub Josef42e568c2018-01-24 13:18:23 +010085 }
86 }
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 }
95 }
96}