#!/usr/bin/env groovy def PROTECTED_BRANCH def BRANCH_ENV = [ test: 'test', master: 'production' ] node { stage('Setup') { env.FRONT_REPLICAS = 1 env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev' PROTECTED_BRANCH = [ 'dev', 'test', 'master' ].contains(env.BRANCH_NAME) // https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables echo "NODE_NAME: ${env.NODE_NAME}" echo "WORKSPACE: ${env.WORKSPACE}" configFileProvider([ configFile(fileId: 'salix-front.properties', variable: 'PROPS_FILE') ]) { def props = readProperties file: PROPS_FILE props.each {key, value -> env."${key}" = value } props.each {key, value -> echo "${key}: ${value}" } } if (PROTECTED_BRANCH) { configFileProvider([ configFile(fileId: "salix-front.branch.${env.BRANCH_NAME}", variable: 'BRANCH_PROPS_FILE') ]) { def props = readProperties file: BRANCH_PROPS_FILE props.each {key, value -> env."${key}" = value } props.each {key, value -> echo "${key}: ${value}" } } } } } pipeline { agent any options { disableConcurrentBuilds() } tools { nodejs 'node-v18' } environment { PROJECT_NAME = 'lilium' } stages { stage('Install') { environment { NODE_ENV = "" } steps { sh 'pnpm install --prefer-offline' } } // UNCOMMENT ME! // stage('Test') { // when { // expression { !PROTECTED_BRANCH } // } // environment { // NODE_ENV = "" // } // steps { // sh 'pnpm run test:unit:ci' // } // post { // always { // junit( // testResults: 'junitresults.xml', // allowEmptyResults: true // ) // } // } // } stage('E2E') { when { expression { !PROTECTED_BRANCH } } environment { CREDENTIALS = credentials('docker-registry') IMAGE = "$REGISTRY/salix-back" } steps { script { def packageJson = readJSON file: 'package.json' env.VERSION = "${packageJson.version}-e2e${env.BUILD_ID}" } // // sh 'docker pull $IMAGE:dev' // sh 'git clone https://gitea.verdnatura.es/verdnatura/salix.git' // // sh 'docker ps -a' // sh 'docker network create salix_default' // sh 'docker-compose -f docker-compose.yml build db' // sh 'docker-compose -f docker-compose.yml up db' // sh 'docker run --name back $IMAGE:dev' sh 'rm -rf salix' sh 'docker-compose down' sh 'docker-compose rm' // sh 'docker rm -f back' // sh 'docker rm -f db' // sh 'docker rm -f front' // sh 'docker rm -f e2e' sh 'git clone --branch dev https://gitea.verdnatura.es/verdnatura/salix.git' // sh 'cd front' // sh '# export VERSION=e2e-try' sh 'docker build -f salix/back/Dockerfile -t back ./salix' sh 'docker-compose -f docker-compose.e2e.yml up -d --build front' sh 'pnpm i @verdnatura/myt' sh 'cd salix && npx myt run -t --ci -d -n front_default' // sh 'docker-compose -f docker-compose.e2e.yml up --build db' sh 'docker run --net=host -v ./test/cypress/storage:/salix/storage -d back' sh 'docker-compose -f docker-compose.e2e.yml up e2e' } post { always { junit( testResults: 'junitresults.xml', allowEmptyResults: true ) } } } stage('Build') { when { expression { PROTECTED_BRANCH } } environment { CREDENTIALS = credentials('docker-registry') } steps { sh 'quasar build' script { def packageJson = readJSON file: 'package.json' env.VERSION = "${packageJson.version}-build${env.BUILD_ID}" } dockerBuild() } } stage('Deploy') { when { expression { PROTECTED_BRANCH } } steps { script { def packageJson = readJSON file: 'package.json' env.VERSION = "${packageJson.version}-build${env.BUILD_ID}" } withKubeConfig([ serverUrl: "$KUBERNETES_API", credentialsId: 'kubernetes', namespace: 'lilium' ]) { sh 'kubectl set image deployment/lilium-$BRANCH_NAME lilium-$BRANCH_NAME=$REGISTRY/salix-frontend:$VERSION' } } } } }