diff --git a/Jenkinsfile b/Jenkinsfile index 726ecc5..a62c3cb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' - } - } - } } -} +} \ No newline at end of file