Update Jenkinsfile

This commit is contained in:
Benjamin Tan 2025-12-15 17:44:59 +00:00
parent 547c27e564
commit 22f175dbfb

77
Jenkinsfile vendored
View file

@ -1,40 +1,69 @@
pipeline { pipeline {
agent docker { image 'python:alpine3.22' } agent {
docker {
image 'python:3.11-slim'
}
}
environment {
APP_PORT = '3001'
}
stages { stages {
stage('Pre-build') {
stage('Install Dependencies') {
steps { steps {
sh 'python3 -m venv venv' sh '''
sh 'source venv/bin/activate' python --version
sh 'pip3 --version' pip install --upgrade pip
sh 'pip install -r requirements.txt' pip install -r requirements.txt
'''
} }
} }
stage('Test') { stage('Unit Tests') {
steps { steps {
sh 'pytest test_app.py' sh 'pytest test_app.py'
} }
} }
stage('Containerization') { stage('Run & Integration Test') {
steps { parallel {
sh 'echo Docker Build Image..'
sh 'echo Docker Tag Image....' stage('Start App') {
sh 'echo Docker Push Image......' steps {
sh '''
gunicorn --bind 0.0.0.0:${APP_PORT} app:app &
echo $! > gunicorn.pid
'''
}
}
stage('Integration Test') {
steps {
sh '''
sleep 5
curl -f http://localhost:${APP_PORT}
'''
}
}
}
post {
always {
sh '''
if [ -f gunicorn.pid ]; then
kill $(cat gunicorn.pid) || true
fi
'''
}
} }
} }
parallel {
stage('Run-and-test') stage('Containerization') {
{ steps {
steps { echo 'Docker Build Image...'
sh 'gunicorn --bind 0.0.0.0:3001 app:app' echo 'Docker Tag Image...'
} echo 'Docker Push Image...'
}
stage('Integration Testing') {
steps {
sh "sleep 10s"
sh 'curl localhost:3001'
}
} }
} }
} }