From 03c61198e62e47a9af53f18e052e764fa228c809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Mattm=C3=BCller?= Date: Wed, 21 Jun 2023 09:49:57 +0200 Subject: [PATCH] jobs: added documentation pipeline as it is referenced in Jcasc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc Mattmüller --- jobs/Jenkinsfile_Documentation | 128 +++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 jobs/Jenkinsfile_Documentation diff --git a/jobs/Jenkinsfile_Documentation b/jobs/Jenkinsfile_Documentation new file mode 100644 index 0000000..e518ad9 --- /dev/null +++ b/jobs/Jenkinsfile_Documentation @@ -0,0 +1,128 @@ +// Loading code requires a NODE context +// But we want the code accessible outside the node Context +// So declare common (object created by the LOAD operation) outside the Node block. +def common + + +// declarative pipeline +pipeline { + agent any + + parameters { + string(name: 'VERSION', defaultValue: '', description: 'The version string of the documentation, e.g. 1.2.3 or empty for latest') + booleanParam(name: 'DO_CLEAN_BUILD', defaultValue: false, description: 'do a clean build, i.e. remove any residuals') + } + + options { + timeout(time: 1, unit: 'HOURS') + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '5')) + } + + environment { + DOC_DIRNAME = "doc" + DOC_DIR = "${WORKSPACE}/${DOC_DIRNAME}" + } + + stages { + + // Check Parameters + //----------------------------- + stage('Check Parameters') { + steps { + script { + // load common file + common = load "${WORKSPACE}/jobs/Jenkinsfile_Common" + printJobParameters() + } + } + } + + // Clean + //----------------------------- + stage('Clean') { + when { expression { return params.DO_CLEAN_BUILD } } + steps { + script { + common.cleaningClonedRepoDir() + } + } + } + + // Prepare + //----------------------------- + stage('Prepare') { + steps { + script{ + setupEnvironment(common, "${params.VERSION}") + printEnvironmentParameters() + setDisplayName() + } + } + } // Prepare + + + // Build Doc + //----------------------------- + stage('Build Documentation') { + steps { + script { + buildDocumentation("${env.DOC_DIR}", "CI Documentation") + } // script + } + } // Build Doc + + } // stages +} + +//--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- +def printJobParameters() { + println "\ +----------------------------------\n\ + Job Parameters:\n\ +----------------------------------\n\ + VERSION = ${params.VERSION}\n\ + DO_CLEAN_BUILD = ${params.DO_CLEAN_BUILD}\n\ +----------------------------------\n" +} +//--------------------------------------------------------------------------------------------------------------------- +def setupEnvironment(commonHelpers, version) { + env.DOC_VERSION = ("${version}" == "") ? "latest" : "${version}" + sh("rm -rf ${DOC_DIRNAME}/*.zip") +} +//--------------------------------------------------------------------------------------------------------------------- +def setDisplayName() { + currentBuild.displayName = "#${env.BUILD_NUMBER}: ${env.DOC_VERSION}" +} +//--------------------------------------------------------------------------------------------------------------------- +def printEnvironmentParameters() { + println "----------------------------------\n\ + Environment Parameters:\n\ + \n\ + --> doc version = ${env.DOC_VERSION}\n\ + --> doc dir = ${env.DOC_DIR}\n\ +----------------------------------\n" +} +//--------------------------------------------------------------------------------------------------------------------- +def buildDocumentation(workDir, docTitle) { + def artifactName = "NWL-CI-Doc-${env.DOC_VERSION}.zip" + println "Building documentation for ${workDir}..." + dir(workDir) { + sh("make clean") + if(sh(returnStatus: true, script: "make html") != 0) { + unstable("UNSTABLE: building ${workDir}") + return + } + println "Archiving documentation (name = ${artifactName}) and publishing HTML..." + zip(archive: true, dir: "out/html", glob: "**/*", zipFile: "${artifactName}") + publishHTML target: [ + allowMissing: false, + alwaysLinkToLastBuild: false, + keepAll: true, + reportDir: 'out/html', + reportFiles: 'index.html', + reportName: docTitle + ] + } +}