| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 1 | /** | 
| Jakub Josef | 5edceb9 | 2018-02-05 17:10:33 +0100 | [diff] [blame] | 2 |  * Pipeline for generating sphinx reclass generated documentation | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 3 |  * MODEL_GIT_URL | 
 | 4 |  * MODEL_GIT_REF | 
 | 5 |  * CLUSTER_NAME | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 6 |  * | 
 | 7 |  */ | 
 | 8 |  | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 9 | common = new com.mirantis.mk.Common() | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 10 | ssh = new com.mirantis.mk.Ssh() | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 11 | gerrit = new com.mirantis.mk.Gerrit() | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 12 | git = new com.mirantis.mk.Git() | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 13 | python = new com.mirantis.mk.Python() | 
 | 14 | salt = new com.mirantis.mk.Salt() | 
 | 15 |  | 
 | 16 | timeout(time: 12, unit: 'HOURS') { | 
 | 17 |   node("python") { | 
 | 18 |     try { | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 19 |        def workspace = common.getWorkspace() | 
 | 20 |        def masterName = "cfg01." + CLUSTER_NAME.replace("-","_") + ".lab" | 
| Jakub Josef | 5edceb9 | 2018-02-05 17:10:33 +0100 | [diff] [blame] | 21 |        def jenkinsUserIds = common.getJenkinsUserIds() | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 22 |        def img = docker.image("tcpcloud/salt-models-testing:nightly") | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 23 |        img.pull() | 
| Jakub Josef | ad56efe | 2018-02-01 13:56:44 +0100 | [diff] [blame] | 24 |        img.inside("-u root:root --hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") { | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 25 |            stage("Prepare salt env") { | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 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") | 
 | 30 |               } | 
 | 31 |               if(checkouted) { | 
 | 32 |                 if (fileExists('classes/system')) { | 
 | 33 |                     ssh.prepareSshAgentKey(CREDENTIALS_ID) | 
 | 34 |                     dir('classes/system') { | 
| Jakub Josef | 5edceb9 | 2018-02-05 17:10:33 +0100 | [diff] [blame] | 35 |                       // XXX: JENKINS-33510 dir step not work properly inside containers, so let's taky reclass system model directly | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 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 |               } | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 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") | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 44 |                     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 Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 53 |            stage("Generate documentation"){ | 
| Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 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"){ | 
| Jakub Josef | 5edceb9 | 2018-02-05 17:10:33 +0100 | [diff] [blame] | 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 && \ | 
 | 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 Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 83 |                     common.errorMsg("Documentation publish stage failed!") | 
| Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 84 |                 } | 
| Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 85 |            } | 
 | 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 | } |