blob: e0262571fe10067462b7eab19a484cbceaa7571a [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"
Jakub Josef22815b02018-01-30 16:05:26 +010028 //def jenkinsUserIds = common.getJenkinsUserIds()
Jakub Josef3d72fa62018-01-24 14:12:53 +010029 def img = docker.image("tcpcloud/salt-models-testing:nightly")
Jakub Josef42e568c2018-01-24 13:18:23 +010030 img.pull()
Jakub Josefad56efe2018-02-01 13:56:44 +010031 img.inside("-u root:root --hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") {
Jakub Josef42e568c2018-01-24 13:18:23 +010032 stage("Prepare salt env") {
Jakub Josef3d72fa62018-01-24 14:12:53 +010033 if(MODEL_GIT_REF != "" && MODEL_GIT_URL != "") {
34 checkouted = gerrit.gerritPatchsetCheckout(MODEL_GIT_URL, MODEL_GIT_REF, "HEAD", CREDENTIALS_ID)
35 } else {
36 throw new Exception("Cannot checkout gerrit patchset, MODEL_GIT_URL or MODEL_GIT_REF is null")
37 }
38 if(checkouted) {
39 if (fileExists('classes/system')) {
40 ssh.prepareSshAgentKey(CREDENTIALS_ID)
41 dir('classes/system') {
42 // XXX: JENKINS-33510 dir step not work properly inside containers
43 //remoteUrl = git.getGitRemote()
44 ssh.ensureKnownHosts("https://github.com/Mirantis/reclass-system-salt-model")
45 }
46 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
47 }
48 }
49 // install all formulas
50 sh("apt-get update && apt-get install -y salt-formula-*")
51 withEnv(["MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${CLUSTER_NAME}", "MINION_ID=${masterName}"]){
52 sh("cp -r ${workspace}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts")
Jakub Josef42e568c2018-01-24 13:18:23 +010053 sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \
54 && source_local_envs \
55 && configure_salt_master \
56 && configure_salt_minion \
57 && install_salt_formula_pkg; \
58 saltservice_restart; \
59 saltmaster_init'""")
60 }
61 }
Jakub Josef42e568c2018-01-24 13:18:23 +010062 stage("Checkout formula review"){
63 if(gerritRef){
64 //TODO: checkout gerrit review and replace formula content in directory
65 // gerrit.gerritPatchsetCheckout([credentialsId: CREDENTIALS_ID])
66 }else{
67 common.successMsg("Test triggered manually, so skipping checkout formula review stage")
68 }
69 }
70 stage("Generate documentation"){
Jakub Josef3d72fa62018-01-24 14:12:53 +010071 def saltResult = sh(script:"salt-call state.sls salt.minion,sphinx.server,nginx", returnStatus:true)
72 if(saltResult > 0){
73 common.warnMsg("Salt call salt.minion,sphinx.server,nginx failed but continuing")
74 }
75 }
76 stage("Publish outputs"){
Jakub Josef22815b02018-01-30 16:05:26 +010077 try{
78 sh("mkdir ${workspace}/output")
79 //TODO: verify existance of created output files
80 // /srv/static/sites/reclass_doc will be used for publishHTML step
81 sh("tar -zcf ${workspace}/output/docs-html.tar.gz /srv/static/sites/reclass_doc")
82 sh("cp -R /srv/static/sites/reclass_doc ${workspace}")
83 publishHTML (target: [
84 reportDir: 'reclass_doc',
85 reportFiles: 'index.html',
86 reportName: "Reclass-documentation"
87 ])
88 // /srv/static/extern will be used as tar artifact
89 sh("tar -zcf ${workspace}/output/docs-src.tar.gz /srv/static/extern")
90 archiveArtifacts artifacts: "output/*"
91 }catch(Exception e){
92 common.errorMsg("Documentation publish stage failed!")
93 }finally{
94 sh("rm -r ./output")
95 }
Jakub Josef42e568c2018-01-24 13:18:23 +010096 }
97 }
98 } catch (Throwable e) {
99 // If there was an error or exception thrown, the build failed
100 currentBuild.result = "FAILURE"
101 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
102 throw e
103 } finally {
104 common.sendNotification(currentBuild.result, "", ["slack"])
105 }
106 }
107}