Files
smartguide/Jenkinsfile
T
arzani 2ef50d9bcf
LocationBasedServices/smartguide/pipeline/head This commit looks good
deprected .env file baked into docker build and jenkins ci pipeline
2026-11-03 14:32:25 +01:00

118 lines
4.0 KiB
Groovy

pipeline {
agent any
environment {
DEPLOY_HOST = 'pg-aiis@apps-dev.nes'
IMAGE_PREFIX = 'inse'
IMAGE_VERSION = '1.0.0'
TARGET_PLATFORM = 'linux/amd64'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
withCredentials([file(credentialsId: 'smartguide-env', variable: 'INSE_ENV_FILE')]) {
sh './gradlew build'
}
}
}
stage('Test') {
steps {
withCredentials([file(credentialsId: 'smartguide-env', variable: 'INSE_ENV_FILE')]) {
sh './gradlew :service:test'
}
}
}
stage('Save Docker image') {
when {
branch 'main'
}
steps {
sh 'docker save ${IMAGE_PREFIX}-app:${IMAGE_VERSION} | gzip > app-image.tar.gz'
}
}
stage('Development Mode') {
when {
not { branch 'main' }
}
steps {
echo '🛠️ Running in development mode — deploy stage skipped.'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
withCredentials([sshUserPrivateKey(
credentialsId: 'aiis-server-key',
keyFileVariable: 'SSH_KEY'
)]) {
sh '''
# Copy backend Docker image to remote machine
scp -i "$SSH_KEY" \
-o StrictHostKeyChecking=no \
app-image.tar.gz \
${DEPLOY_HOST}:~/tmp/
# Load and restart backend container on remote machine
ssh -i "$SSH_KEY" \
-o StrictHostKeyChecking=no \
${DEPLOY_HOST} "
docker load < ~/tmp/app-image.tar.gz &&
docker stop inse-app || true &&
docker rm inse-app || true &&
docker run -d \
--name inse-app \
-p 8080:8000 \
${IMAGE_PREFIX}-app:${IMAGE_VERSION} run
"
# Deploy frontend static files
rsync -azO --delete \
--no-perms \
--cvs-exclude \
--exclude='/.htaccess' \
-e "ssh -i $SSH_KEY -o StrictHostKeyChecking=no" \
webapp/dist/inse/browser/ \
${DEPLOY_HOST}:/var/www/smartguide
'''
}
}
}
}
post {
success {
slackSend teamDomain: 'pgaiis',
channel: '#jenkins',
color: 'good',
message: "✅ *Build SUCCESS*: ${env.JOB_NAME} #${env.BUILD_NUMBER}\n" +
"Branch: `${env.BRANCH_NAME}` | Duration: ${currentBuild.durationString}\n" +
"Console: ${env.BUILD_URL}console"
}
failure {
slackSend teamDomain: 'pgaiis',
channel: '#jenkins',
color: 'danger',
message: "❌ *Build FAILED*: ${env.JOB_NAME} #${env.BUILD_NUMBER}\n" +
"Branch: `${env.BRANCH_NAME}` | Duration: ${currentBuild.durationString}\n" +
"Failed stage: ${env.STAGE_NAME ?: 'unknown'}\n" +
"Console: ${env.BUILD_URL}console"
}
always {
sh 'rm -f app-image.tar.gz'
}
}
}