blob: cf11e4a5ba829c37268cb996eb2e09f49bc877b8 [file] [log] [blame]
Jakub Josef42e568c2018-01-24 13:18:23 +01001/**
2 * Pipeline for generating and testing sphinx 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
9def gerritRef
10try {
11 gerritRef = GERRIT_REFSPEC
12} catch (MissingPropertyException e) {
13 gerritRef = null
14}
15
16common = new com.mirantis.mk.Common()
Jakub Josef3d72fa62018-01-24 14:12:53 +010017ssh = new com.mirantis.mk.Ssh()
Jakub Josef42e568c2018-01-24 13:18:23 +010018gerrit = new com.mirantis.mk.Gerrit()
Jakub Josef3d72fa62018-01-24 14:12:53 +010019git = new com.mirantis.mk.Git()
Jakub Josef42e568c2018-01-24 13:18:23 +010020python = new com.mirantis.mk.Python()
21salt = new com.mirantis.mk.Salt()
22
23timeout(time: 12, unit: 'HOURS') {
24 node("python") {
25 try {
Jakub Josef3d72fa62018-01-24 14:12:53 +010026 def workspace = common.getWorkspace()
27 def masterName = "cfg01." + CLUSTER_NAME.replace("-","_") + ".lab"
28 def img = docker.image("tcpcloud/salt-models-testing:nightly")
Jakub Josef42e568c2018-01-24 13:18:23 +010029 img.pull()
Jakub Josef3d72fa62018-01-24 14:12:53 +010030 img.inside("-u root:root --hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") {
Jakub Josef42e568c2018-01-24 13:18:23 +010031 stage("Prepare salt env") {
Jakub Josef3d72fa62018-01-24 14:12:53 +010032 if(MODEL_GIT_REF != "" && MODEL_GIT_URL != "") {
33 checkouted = gerrit.gerritPatchsetCheckout(MODEL_GIT_URL, MODEL_GIT_REF, "HEAD", CREDENTIALS_ID)
34 } else {
35 throw new Exception("Cannot checkout gerrit patchset, MODEL_GIT_URL or MODEL_GIT_REF is null")
36 }
37 if(checkouted) {
38 if (fileExists('classes/system')) {
39 ssh.prepareSshAgentKey(CREDENTIALS_ID)
40 dir('classes/system') {
41 // XXX: JENKINS-33510 dir step not work properly inside containers
42 //remoteUrl = git.getGitRemote()
43 ssh.ensureKnownHosts("https://github.com/Mirantis/reclass-system-salt-model")
44 }
45 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
46 }
47 }
48 // install all formulas
49 sh("apt-get update && apt-get install -y salt-formula-*")
50 withEnv(["MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${CLUSTER_NAME}", "MINION_ID=${masterName}"]){
51 sh("cp -r ${workspace}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts")
Jakub Josef42e568c2018-01-24 13:18:23 +010052 sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \
53 && source_local_envs \
54 && configure_salt_master \
55 && configure_salt_minion \
56 && install_salt_formula_pkg; \
57 saltservice_restart; \
58 saltmaster_init'""")
59 }
60 }
Jakub Josef42e568c2018-01-24 13:18:23 +010061 stage("Checkout formula review"){
62 if(gerritRef){
63 //TODO: checkout gerrit review and replace formula content in directory
64 // gerrit.gerritPatchsetCheckout([credentialsId: CREDENTIALS_ID])
65 }else{
66 common.successMsg("Test triggered manually, so skipping checkout formula review stage")
67 }
68 }
69 stage("Generate documentation"){
Jakub Josef3d72fa62018-01-24 14:12:53 +010070 def saltResult = sh(script:"salt-call state.sls salt.minion,sphinx.server,nginx", returnStatus:true)
71 if(saltResult > 0){
72 common.warnMsg("Salt call salt.minion,sphinx.server,nginx failed but continuing")
73 }
74 }
75 stage("Publish outputs"){
76 sh("mkdir ${workspace}/output")
77 //TODO: verify existance of created output files
78 // /srv/static/sites/reclass_doc will be used for publishHTML step
79 sh("tar -zcf ${workspace}/output/docs-html.tar.gz /srv/static/sites/reclass_doc")
80 sh("cp -R /srv/static/sites/reclass_doc ${workspace}")
81 publishHTML (target: [
82 allowMissing: false,
83 alwaysLinkToLastBuild: false,
84 keepAll: true,
85 reportDir: 'reclass_doc',
86 reportFiles: 'index.html',
87 reportName: "Reclass documentation"
88 ])
89 // /srv/static/extern will be used as tar artifact
90 sh("tar -zcf ${workspace}/output/docs-src.tar.gz /srv/static/extern")
91 archiveArtifacts artifacts: "output/*"
Jakub Josef42e568c2018-01-24 13:18:23 +010092 }
93 }
94 } catch (Throwable e) {
95 // If there was an error or exception thrown, the build failed
96 currentBuild.result = "FAILURE"
97 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
98 throw e
99 } finally {
100 common.sendNotification(currentBuild.result, "", ["slack"])
101 }
102 }
103}