Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Pipeline for generating and testing sphinx 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 | |
| 9 | def gerritRef |
| 10 | try { |
| 11 | gerritRef = GERRIT_REFSPEC |
| 12 | } catch (MissingPropertyException e) { |
| 13 | gerritRef = null |
| 14 | } |
| 15 | |
| 16 | common = new com.mirantis.mk.Common() |
Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 17 | ssh = new com.mirantis.mk.Ssh() |
Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 18 | gerrit = new com.mirantis.mk.Gerrit() |
Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 19 | git = new com.mirantis.mk.Git() |
Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 20 | python = new com.mirantis.mk.Python() |
| 21 | salt = new com.mirantis.mk.Salt() |
| 22 | |
| 23 | timeout(time: 12, unit: 'HOURS') { |
| 24 | node("python") { |
| 25 | try { |
Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 26 | def workspace = common.getWorkspace() |
| 27 | def masterName = "cfg01." + CLUSTER_NAME.replace("-","_") + ".lab" |
Jakub Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 28 | //def jenkinsUserIds = common.getJenkinsUserIds() |
Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 29 | def img = docker.image("tcpcloud/salt-models-testing:nightly") |
Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 30 | img.pull() |
Jakub Josef | ad56efe | 2018-02-01 13:56:44 +0100 | [diff] [blame] | 31 | 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] | 32 | stage("Prepare salt env") { |
Jakub Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 33 | 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 Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 53 | 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 Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 62 | 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 Josef | 3d72fa6 | 2018-01-24 14:12:53 +0100 | [diff] [blame] | 71 | 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 Josef | 22815b0 | 2018-01-30 16:05:26 +0100 | [diff] [blame] | 77 | 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 Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame] | 96 | } |
| 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 | } |