pipeline { agent any options { disableConcurrentBuilds() buildDiscarder(logRotator(numToKeepStr: '10')) } parameters { string( name: 'CONF_PREFIX', defaultValue: 'production-', description: 'Will be appended with the language' ) string( name: 'LANGUAGES', defaultValue: 'en fr', description: 'Space-separated list of locales to build' ) booleanParam(name: 'SKIP_TESTS', defaultValue: true, description: 'Skip tests') string( name: 'PUBLISH_URL', defaultValue: 'https://nexus.valuya.be/nexus/repository', description: 'Deployment repository url' ) string( name: 'PUBLISH_REPO', defaultValue: 'web-snapshots', description: 'Deployment repository' ) } stages { stage ('Install') { steps { nodejs(nodeJSInstallationName: 'node 10', configId: 'npm-global-config') { ansiColor('xterm') { sh ''' rm -rfv dist* npm install ''' } } } } stage ('Build') { steps { withCredentials([usernameColonPassword(credentialsId: 'nexus-basic-auth', variable: 'NEXUS_BASIC_AUTH')]) { nodejs(nodeJSInstallationName: 'node 10', configId: 'npm-global-config') { catchError { ansiColor('xterm') { sh ''' export DATE="$(date -Iseconds)" export COMMIT="$(git rev-parse --short HEAD)" echo '{"date":"'$DATE'","commit": "'$COMMIT'"}' > src/assets/buildinfo.json for LANG in $LANGUAGES ; do CONF_NAME="${CONF_PREFIX}${LANG}" ./node_modules/.bin/ng build \ -c "$CONF_NAME" done ''' } }}} } } stage ('Publish') { steps { withCredentials([usernameColonPassword(credentialsId: 'nexus-basic-auth', variable: 'NEXUS_BASIC_AUTH')]) { ansiColor('xterm') { nodejs(nodeJSInstallationName: 'node 10', configId: 'npm-global-config') { sh ''' export DATE="$(date -Iseconds)" export COMMIT="$(git rev-parse --short HEAD)" for LANG in $LANGUAGES ; do export ARCHIVE="charlyghislaindotcom-${COMMIT}-$LANG.tgz" # Compress cd dist/${LANG}/ tar -cvzf ../${ARCHIVE} ./ cd ../.. # Upload archives curl -v --user $NEXUS_BASIC_AUTH --upload-file dist/${ARCHIVE} \ ${PUBLISH_URL}/${PUBLISH_REPO}/com/charlyghislain/charlyghislaindotcom/${ARCHIVE} # Create .latest 'links' (branch heads) if required if [ "${BRANCH_NAME}" = "master" ] ; then export ARCHIVE_LINK="master.${LANG}.latest" echo "$ARCHIVE" > ./${ARCHIVE_LINK} curl -v --user $NEXUS_BASIC_AUTH --upload-file ./${ARCHIVE_LINK} \ ${PUBLISH_URL}/${PUBLISH_REPO}/com/charlyghislain/charlyghislaindotcom/${ARCHIVE_LINK} elif [ "${BRANCH_NAME}" = "dev" ] ; then export ARCHIVE_LINK="dev.${LANG}.latest" echo "$ARCHIVE" > ./${ARCHIVE_LINK} curl -v --user $NEXUS_BASIC_AUTH --upload-file ./${ARCHIVE_LINK} \ ${PUBLISH_URL}/${PUBLISH_REPO}/com/charlyghislain/charlyghislaindotcom/${ARCHIVE_LINK} fi done ''' } } } } } stage ("Update cluster state") { steps { build job: 'infra/cluster-conf-update', parameters: [ string(name:"STACK", value:"charlyghislaindotcom"), string(name:"VALUES_FILE", value:"values.yaml"), string(name:"VALUES_KEY", value:".deployment.imageTag"), string(name:"VALUES_VALUE", value:"\"${params.NEW_VERSION}\""), ] } } } }