Jenkinsfile 1.86 KB
Newer Older
Laurent Leseigneur's avatar
Laurent Leseigneur committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/env groovy

boolean isVersionSupported(version, supportedVersions) {
    def result = false
    for (supported in supportedVersions.tokenize(',')) {
        if (supported == version) {
            result = true
            break
        }
    }
    def status = result ? 'supported' : 'NOT supported'
    println "Version <$version> is $status on this environment."
    return result
}


node {
    stage 'Checkout'
    def branch_name = env.BRANCH_NAME
    println "Checking out branch $branch_name"
    checkout scm
    
    stage 'Build'
    def nodejsHome = tool name: 'NodeJS_424', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
    sh """#!/bin/bash
set -e

env | sort -u

echo "### Cleaning previous build (except index.html)"
shopt -s extglob
rm -rf build
echo ""

echo "### Converting .md to .html"
PATH=\$PATH:${nodejsHome}/bin
npm install
38
scripts/convertMdToHtml.js bici
Laurent Leseigneur's avatar
Laurent Leseigneur committed
39 40 41 42
scripts/taxonomy.js
echo ""

echo "### Creating doc html archive"
43 44 45 46
archive_name=doc-bici-html-\$BRANCH_NAME-`date +"%Y%m%d_%H%M%S"`.tar.gz
rm -rf doc-bici-html*.tar.gz doc-bici-html
mkdir doc-bici-html && ln -s ../build/html doc-bici-html/html && ln -s ../md/images doc-bici-html/images
tar czf \$archive_name --dereference doc-bici-html
Laurent Leseigneur's avatar
Laurent Leseigneur committed
47 48 49 50 51 52 53
echo ". Generated archive: \$archive_name"
echo ""

echo "Done."
"""

    stage 'Archive'
54
    archive '**/doc-bici-html*.tar.gz'
Laurent Leseigneur's avatar
Laurent Leseigneur committed
55 56 57
    
    stage 'Deploy'
    parallel preprod: {
58
        if (isVersionSupported(branch_name, env.GLOBAL_PREPROD_BICI_VERSIONS)) {
Laurent Leseigneur's avatar
Laurent Leseigneur committed
59 60 61
            build job: 'push-content-preprod', parameters: [[$class: 'StringParameterValue', name: 'ARE_YOU_SURE', value: 'Yes']]
        }
    }, prod: {
62
        if (isVersionSupported(branch_name, env.GLOBAL_PROD_BICI_VERSIONS)) {
Laurent Leseigneur's avatar
Laurent Leseigneur committed
63 64 65 66 67
            build job: 'push-content-prod', parameters: [[$class: 'StringParameterValue', name: 'ARE_YOU_SURE', value: 'Yes']]
        }
    },
    failFast: false
}