Skip to main content

CI/CD Pipeline

Overview

Centralize Management System menggunakan Jenkins untuk CI/CD pipeline.

Jenkinsfile

Pipeline Stages

pipeline {
agent {
label 'Server-TSG-VM01'
}

options {
disableConcurrentBuilds()
timeout(time: 15, unit: 'MINUTES')
}

environment {
KUBE_CONFIG = '/opt/clm/k3s/k3s.yaml'
CONFIGS_DIR = '/opt/clm/configs'
ENV_FILE_BE = '/home/jenkins/secret/.env.bjbs-clm-be'
ENV_FILE_FE = '/home/jenkins/secret/.env.bjbs-clm-fe'
FRONTEND_IMAGE = 'clm-frontend:latest'
}

stages {
stage('Checkout') {
steps {
checkout scm
}
}

stage('Sync Configs') {
steps {
sh '''
sudo mkdir -p ${CONFIGS_DIR}
sudo rsync -av --delete configs/ ${CONFIGS_DIR}/
'''
}
}

stage('Build') {
parallel {
stage('Build Backend') {
steps {
sh 'docker compose build backend'
}
}
stage('Build Frontend') {
steps {
sh """
docker build \
--no-cache \
--build-arg VITE_API_BASE_URL=\${VITE_API_BASE_URL:-http://10.8.0.48:8081} \
-f frontend/Dockerfile.prod \
-t ${FRONTEND_IMAGE} \
frontend/
"""
}
}
stage('Build Fluentd') {
steps {
sh 'docker compose build fluentd'
}
}
}
}

stage('Deploy Backend') {
steps {
sh '''
export CONFIGS_DIR=${CONFIGS_DIR}
docker compose \
--env-file ${ENV_FILE_BE} \
up -d --force-recreate backend fluentd \
--build
'''
}
}

stage('Deploy Frontend') {
steps {
sh '''
docker compose \
--env-file ${ENV_FILE_FE} \
up -d --force-recreate frontend
'''
}
}

stage('Health Check') {
options {
timeout(time: 90, unit: 'SECONDS')
}
steps {
sh '''
sleep 30

OK=0; FAIL=0

curl -sf http://localhost:8081/healthz > /dev/null && echo "✅ backend" || { echo "❌ backend"; FAIL=$((FAIL+1)); }
curl -sf http://localhost:8085 > /dev/null && echo "✅ frontend" || { echo "❌ frontend"; FAIL=$((FAIL+1)); }

[ "$FAIL" -gt 0 ] && exit 1 || echo "All services healthy ✅"
'''
}
}

stage('Cleanup') {
steps {
sh 'docker builder prune -f'
}
}
}

post {
success {
echo '✅ Pipeline completed successfully'
}
failure {
echo '❌ Pipeline failed'
}
}
}

Pipeline Flow

┌──────────┐     ┌──────────┐     ┌──────────┐     ┌──────────┐
│ Checkout │────▶│ Sync │────▶│ Build │────▶│ Deploy │
│ │ │ Configs │ │ (Parallel│ │ │
└──────────┘ └──────────┘ └──────────┘ └──────────┘


┌──────────┐
│ Health │
│ Check │
└──────────┘

Environment Variables

VariableDescriptionLocation
KUBE_CONFIGK3s kubeconfig/opt/clm/k3s/k3s.yaml
CONFIGS_DIRConfigs directory/opt/clm/configs
ENV_FILE_BEBackend env file/home/jenkins/secret/.env.bjbs-clm-be
ENV_FILE_FEFrontend env file/home/jenkins/secret/.env.bjbs-clm-fe

Health Checks

ServiceCheckExpected
Backendcurl http://localhost:8081/healthz200 OK
Frontendcurl http://localhost:8085200 OK
Fluentddocker exec fluentd cat /fluentd/etc/fluent.confSuccess
Camelcurl http://localhost:8181/actuator/health200 OK
Prometheuscurl http://localhost:9090/-/healthy200 OK
Grafanacurl http://localhost:3001/api/health200 OK
RabbitMQcurl http://localhost:15672/api/overview200 OK
MinIOcurl http://localhost:9000/minio/health/live200 OK

Manual Deployment

Build & Deploy All

# Build all services
docker compose build

# Deploy all services
docker compose up -d --force-recreate

Deploy Specific Service

# Deploy backend only
docker compose up -d --force-recreate backend

# Deploy frontend only
docker compose up -d --force-recreate frontend

Next Steps