Jakub Josef | 42e568c | 2018-01-24 13:18:23 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * Pipeline for generating and testing sphinx generated documentation |
| 3 | * |
| 4 | * Parameters: |
| 5 | * SALT_MASTER_URL |
| 6 | * SALT_MASTER_CREDENTIALS |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | def gerritRef |
| 11 | try { |
| 12 | gerritRef = GERRIT_REFSPEC |
| 13 | } catch (MissingPropertyException e) { |
| 14 | gerritRef = null |
| 15 | } |
| 16 | |
| 17 | common = new com.mirantis.mk.Common() |
| 18 | gerrit = new com.mirantis.mk.Gerrit() |
| 19 | python = new com.mirantis.mk.Python() |
| 20 | salt = new com.mirantis.mk.Salt() |
| 21 | |
| 22 | timeout(time: 12, unit: 'HOURS') { |
| 23 | node("python") { |
| 24 | try { |
| 25 | def masterName = "cfg01.test-salt-formulas-docs.lab" |
| 26 | def img = docker.image("tcpcloud/salt-models-testing:latest") |
| 27 | img.pull() |
| 28 | img.inside("-u root:root --hostname ${masterName}--ulimit nofile=4096:8192 --cpus=2") { |
| 29 | stage("Prepare salt env") { |
| 30 | withEnv(["MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=test-salt-formulas-docs-cluster", "MINION_ID=${masterName}"]){ |
| 31 | //TODO: we need to have some simple model or maybe not, bootstrap.sh script generates test model |
| 32 | //sh("cp -r ${testDir}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts") |
| 33 | sh("echo '127.0.1.2 salt' >> /etc/hosts") |
| 34 | // sedding apt to internal - should be not necessary |
| 35 | sh("cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt-mk.mirantis.com/apt.mirantis.net:8085/g' {} \\;") |
| 36 | sh("cd /srv/salt && find . -type f \\( -name '*.yml' -or -name '*.sh' \\) -exec sed -i 's/apt.mirantis.com/apt.mirantis.net:8085/g' {} \\;") |
| 37 | sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \ |
| 38 | && source_local_envs \ |
| 39 | && configure_salt_master \ |
| 40 | && configure_salt_minion \ |
| 41 | && install_salt_formula_pkg; \ |
| 42 | saltservice_restart; \ |
| 43 | saltmaster_init'""") |
| 44 | } |
| 45 | } |
| 46 | stage("Install all formulas"){ |
| 47 | sh("apt update && apt install -y salt-formula-*") |
| 48 | } |
| 49 | stage("Checkout formula review"){ |
| 50 | if(gerritRef){ |
| 51 | //TODO: checkout gerrit review and replace formula content in directory |
| 52 | // gerrit.gerritPatchsetCheckout([credentialsId: CREDENTIALS_ID]) |
| 53 | }else{ |
| 54 | common.successMsg("Test triggered manually, so skipping checkout formula review stage") |
| 55 | } |
| 56 | } |
| 57 | stage("Generate documentation"){ |
| 58 | def pepperEnv = common.getWorkspace() + "/venvPepper" |
| 59 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 60 | salt.enforceState(venvPepper, masterName , 'sphinx' , true) |
| 61 | } |
| 62 | } |
| 63 | } catch (Throwable e) { |
| 64 | // If there was an error or exception thrown, the build failed |
| 65 | currentBuild.result = "FAILURE" |
| 66 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 67 | throw e |
| 68 | } finally { |
| 69 | common.sendNotification(currentBuild.result, "", ["slack"]) |
| 70 | } |
| 71 | } |
| 72 | } |