blob: 88b29ec9993850fb9184eab1ffc8e3b561529dbd [file] [log] [blame]
/**
* Pipeline for generating and testing sphinx generated documentation
* MODEL_GIT_URL
* MODEL_GIT_REF
* CLUSTER_NAME
*
*/
def gerritRef
try {
gerritRef = GERRIT_REFSPEC
} catch (MissingPropertyException e) {
gerritRef = null
}
common = new com.mirantis.mk.Common()
ssh = new com.mirantis.mk.Ssh()
gerrit = new com.mirantis.mk.Gerrit()
git = new com.mirantis.mk.Git()
python = new com.mirantis.mk.Python()
salt = new com.mirantis.mk.Salt()
timeout(time: 12, unit: 'HOURS') {
node("python") {
try {
def workspace = common.getWorkspace()
def masterName = "cfg01." + CLUSTER_NAME.replace("-","_") + ".lab"
//def jenkinsUserIds = common.getJenkinsUserIds()
def img = docker.image("tcpcloud/salt-models-testing:nightly")
img.pull()
img.inside("--hostname ${masterName} --ulimit nofile=4096:8192 --cpus=2") {
stage("Prepare salt env") {
if(MODEL_GIT_REF != "" && MODEL_GIT_URL != "") {
checkouted = gerrit.gerritPatchsetCheckout(MODEL_GIT_URL, MODEL_GIT_REF, "HEAD", CREDENTIALS_ID)
} else {
throw new Exception("Cannot checkout gerrit patchset, MODEL_GIT_URL or MODEL_GIT_REF is null")
}
if(checkouted) {
if (fileExists('classes/system')) {
ssh.prepareSshAgentKey(CREDENTIALS_ID)
dir('classes/system') {
// XXX: JENKINS-33510 dir step not work properly inside containers
//remoteUrl = git.getGitRemote()
ssh.ensureKnownHosts("https://github.com/Mirantis/reclass-system-salt-model")
}
ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
}
}
// install all formulas
sh("apt-get update && apt-get install -y salt-formula-*")
withEnv(["MASTER_HOSTNAME=${masterName}", "CLUSTER_NAME=${CLUSTER_NAME}", "MINION_ID=${masterName}"]){
sh("cp -r ${workspace}/* /srv/salt/reclass && echo '127.0.1.2 salt' >> /etc/hosts")
sh("""bash -c 'source /srv/salt/scripts/bootstrap.sh; cd /srv/salt/scripts \
&& source_local_envs \
&& configure_salt_master \
&& configure_salt_minion \
&& install_salt_formula_pkg; \
saltservice_restart; \
saltmaster_init'""")
}
}
stage("Checkout formula review"){
if(gerritRef){
//TODO: checkout gerrit review and replace formula content in directory
// gerrit.gerritPatchsetCheckout([credentialsId: CREDENTIALS_ID])
}else{
common.successMsg("Test triggered manually, so skipping checkout formula review stage")
}
}
stage("Generate documentation"){
def saltResult = sh(script:"salt-call state.sls salt.minion,sphinx.server,nginx", returnStatus:true)
if(saltResult > 0){
common.warnMsg("Salt call salt.minion,sphinx.server,nginx failed but continuing")
}
}
stage("Publish outputs"){
try{
sh("mkdir ${workspace}/output")
//TODO: verify existance of created output files
// /srv/static/sites/reclass_doc will be used for publishHTML step
sh("tar -zcf ${workspace}/output/docs-html.tar.gz /srv/static/sites/reclass_doc")
sh("cp -R /srv/static/sites/reclass_doc ${workspace}")
publishHTML (target: [
reportDir: 'reclass_doc',
reportFiles: 'index.html',
reportName: "Reclass-documentation"
])
// /srv/static/extern will be used as tar artifact
sh("tar -zcf ${workspace}/output/docs-src.tar.gz /srv/static/extern")
archiveArtifacts artifacts: "output/*"
}catch(Exception e){
common.errorMsg("Documentation publish stage failed!")
}finally{
sh("rm -r ./output")
}
}
}
} catch (Throwable e) {
// If there was an error or exception thrown, the build failed
currentBuild.result = "FAILURE"
currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
throw e
} finally {
common.sendNotification(currentBuild.result, "", ["slack"])
}
}
}