Update Jenkinsfile

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

81
Jenkinsfile vendored
View file

@ -1,41 +1,70 @@
pipeline {
agent docker { image 'python:alpine3.22' }
agent {
docker {
image 'python:3.11-slim'
}
}
environment {
APP_PORT = '3001'
}
stages {
stage('Pre-build') {
stage('Install Dependencies') {
steps {
sh 'python3 -m venv venv'
sh 'source venv/bin/activate'
sh 'pip3 --version'
sh 'pip install -r requirements.txt'
sh '''
python --version
pip install --upgrade pip
pip install -r requirements.txt
'''
}
}
stage('Test') {
stage('Unit Tests') {
steps {
sh 'pytest test_app.py'
}
}
stage('Run & Integration Test') {
parallel {
stage('Start App') {
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
'''
}
}
}
stage('Containerization') {
steps {
sh 'echo Docker Build Image..'
sh 'echo Docker Tag Image....'
sh 'echo Docker Push Image......'
echo 'Docker Build Image...'
echo 'Docker Tag Image...'
echo 'Docker Push Image...'
}
}
parallel {
stage('Run-and-test')
{
steps {
sh 'gunicorn --bind 0.0.0.0:3001 app:app'
}
}
stage('Integration Testing') {
steps {
sh "sleep 10s"
sh 'curl localhost:3001'
}
}
}
}
}
}