2022-03-29 10:53:02 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-02-05 08:42:21 +00:00
|
|
|
|
|
|
|
def PROTECTED_BRANCH
|
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
def BRANCH_ENV = [
|
|
|
|
test: 'test',
|
2024-12-05 07:50:06 +00:00
|
|
|
master: 'production',
|
|
|
|
beta: 'production'
|
2024-02-20 13:40:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
node {
|
|
|
|
stage('Setup') {
|
2024-02-21 06:31:48 +00:00
|
|
|
env.FRONT_REPLICAS = 1
|
2024-02-20 13:40:35 +00:00
|
|
|
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
|
|
|
|
|
|
|
|
PROTECTED_BRANCH = [
|
|
|
|
'dev',
|
|
|
|
'test',
|
2024-12-05 07:50:06 +00:00
|
|
|
'master',
|
|
|
|
'beta'
|
2024-02-20 13:40:35 +00:00
|
|
|
].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}"
|
2024-02-05 08:42:21 +00:00
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
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}" }
|
|
|
|
}
|
2024-02-05 08:42:21 +00:00
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
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}" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 08:42:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 10:53:02 +00:00
|
|
|
pipeline {
|
|
|
|
agent any
|
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
}
|
2024-02-20 14:05:50 +00:00
|
|
|
tools {
|
|
|
|
nodejs 'node-v18'
|
|
|
|
}
|
2022-03-29 10:53:02 +00:00
|
|
|
environment {
|
2022-04-01 06:33:26 +00:00
|
|
|
PROJECT_NAME = 'lilium'
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Install') {
|
|
|
|
environment {
|
|
|
|
NODE_ENV = ""
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-26 11:33:06 +00:00
|
|
|
sh 'pnpm install --prefer-offline'
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-19 06:58:22 +00:00
|
|
|
// stage('Test: Unit') {
|
|
|
|
// when {
|
|
|
|
// expression { !PROTECTED_BRANCH }
|
|
|
|
// }
|
|
|
|
// environment {
|
|
|
|
// NODE_ENV = ""
|
|
|
|
// }
|
|
|
|
// steps {
|
|
|
|
// sh 'pnpm run test:unit:ci'
|
|
|
|
// }
|
|
|
|
// post {
|
|
|
|
// always {
|
|
|
|
// junit(
|
|
|
|
// testResults: 'junitresults.xml',
|
|
|
|
// allowEmptyResults: true
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2025-01-31 13:58:02 +00:00
|
|
|
stage('Test: E2E') {
|
|
|
|
when {
|
|
|
|
expression { !PROTECTED_BRANCH }
|
|
|
|
}
|
|
|
|
environment {
|
2025-02-03 06:53:43 +00:00
|
|
|
NODE_ENV = ""
|
2025-01-31 13:58:02 +00:00
|
|
|
CREDENTIALS = credentials('docker-registry')
|
|
|
|
}
|
2025-02-03 07:18:05 +00:00
|
|
|
stages {
|
2025-02-03 07:47:11 +00:00
|
|
|
stage('Setup') {
|
2025-02-03 07:21:17 +00:00
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2025-02-10 06:44:52 +00:00
|
|
|
env.NETWORK = "${PROJECT_NAME}-${env.BRANCH_NAME}-${env.BUILD_ID}"
|
2025-02-03 07:21:17 +00:00
|
|
|
cleanDockerE2E()
|
2025-02-10 06:44:52 +00:00
|
|
|
sh "pnpm exec cypress install"
|
2025-02-18 13:49:09 +00:00
|
|
|
// sh "docker build -t cypress-setup:latest -f ./test/cypress/Dockerfile ."
|
2025-02-03 07:21:17 +00:00
|
|
|
}
|
2025-02-10 12:05:52 +00:00
|
|
|
|
2025-01-31 13:56:42 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-13 08:54:09 +00:00
|
|
|
stage('Run') {
|
2025-02-11 14:41:19 +00:00
|
|
|
steps {
|
|
|
|
script {
|
2025-02-19 06:45:00 +00:00
|
|
|
sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d"
|
2025-02-19 07:23:08 +00:00
|
|
|
def containerId = sh(script: """
|
2025-02-19 07:29:17 +00:00
|
|
|
docker run --network ${env.NETWORK}_default \
|
2025-02-19 07:23:08 +00:00
|
|
|
-e TZ=Europe/Madrid \
|
|
|
|
-e DOCKER=true \
|
|
|
|
-e CI=true \
|
2025-02-19 07:26:45 +00:00
|
|
|
-v .:/app \
|
2025-02-19 07:23:08 +00:00
|
|
|
-w /app \
|
|
|
|
cypress-setup:latest \
|
|
|
|
sh -c "while [ ! -d node_modules/cypress ]; do sleep 1; done && pnpm exec cypress run --browser chromium"
|
|
|
|
""", returnStdout: true).trim()
|
2025-02-19 07:19:54 +00:00
|
|
|
checkErrors(containerId)
|
|
|
|
}
|
2025-02-03 12:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-03 06:58:34 +00:00
|
|
|
}
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
cleanDockerE2E()
|
2025-01-31 13:58:02 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-12 08:25:12 +00:00
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
stage('Build') {
|
2024-02-05 08:42:21 +00:00
|
|
|
when {
|
|
|
|
expression { PROTECTED_BRANCH }
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
environment {
|
|
|
|
CREDENTIALS = credentials('docker-registry')
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-20 14:05:50 +00:00
|
|
|
sh 'quasar build'
|
2024-02-21 11:08:49 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:40:04 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-21 11:08:49 +00:00
|
|
|
}
|
2024-02-21 11:04:55 +00:00
|
|
|
dockerBuild()
|
2022-03-30 13:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Deploy') {
|
2024-02-05 08:42:21 +00:00
|
|
|
when {
|
|
|
|
expression { PROTECTED_BRANCH }
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
steps {
|
2024-02-20 14:05:50 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
2024-06-12 05:40:04 +00:00
|
|
|
env.VERSION = "${packageJson.version}-build${env.BUILD_ID}"
|
2024-02-20 14:05:50 +00:00
|
|
|
}
|
2024-05-27 11:31:40 +00:00
|
|
|
withKubeConfig([
|
|
|
|
serverUrl: "$KUBERNETES_API",
|
|
|
|
credentialsId: 'kubernetes',
|
|
|
|
namespace: 'lilium'
|
|
|
|
]) {
|
|
|
|
sh 'kubectl set image deployment/lilium-$BRANCH_NAME lilium-$BRANCH_NAME=$REGISTRY/salix-frontend:$VERSION'
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
2024-01-29 07:38:55 +00:00
|
|
|
}
|
2025-01-31 13:18:16 +00:00
|
|
|
|
|
|
|
def cleanDockerE2E() {
|
|
|
|
script {
|
2025-02-19 06:58:22 +00:00
|
|
|
sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml down || true"
|
2025-02-19 07:17:58 +00:00
|
|
|
// if (containerId?.trim()) {
|
|
|
|
// sh "docker rm ${containerId} || true"
|
|
|
|
// }
|
2025-01-31 13:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-10 12:05:52 +00:00
|
|
|
|
2025-02-19 07:16:47 +00:00
|
|
|
|
2025-02-19 06:45:00 +00:00
|
|
|
def checkErrors(String containerId) {
|
|
|
|
echo "Container ID: ${containerId}"
|
|
|
|
def exitCode = sh(script: "docker inspect -f '{{.State.ExitCode}}' ${containerId}", returnStdout: true).trim()
|
|
|
|
echo "Exit code: ${exitCode}"
|
|
|
|
if (exitCode != '0') {
|
|
|
|
def logs = sh(script: "docker logs ${containerId}", returnStdout: true).trim()
|
|
|
|
error("Cypress E2E tests failed with exit code: ${exitCode}\nLogs:\n${logs}")
|
2025-02-10 14:23:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|