This commit is contained in:
2026-02-18 01:05:05 +01:00
commit 490fad15c6
19 changed files with 558 additions and 0 deletions

149
s3_api/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,149 @@
def vaultConfig() {
return [
vaultUrl: '172.17.0.3:8200',
credentialsId: 'vault-approle',
engineVersion: 2
]
}
def vaultSecrets() {
return [[
path: 'secret/data/companyTransferMoneyService',
secretValues: [
[envVar: 'API_KEY', vaultKey: 'api_key'],
[envVar: 'SELENIUM_GRID', vaultKey: 'selenium_grid_url']
]
]]
}
pipeline {
agent {
docker {
image 'python:3.12-slim'
label 'python3.12'
args '-v /tmp:/tmp' // Optional: Mount /tmp for caching, etc.
}
}
environment {
PYTHON_VERSION = "3.12"
AWS_REGION = "eu-central-1"
S3_BUCKET = "Company-ci-executions"
SERVICE_NAME = "companyTransferMoneyService"
}
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr: '20'))
}
stages {
stage('Checkout') {
agent { label 'ubuntu' }
steps {
checkout scm
}
}
stage('Setup Environment') {
steps {
sh '''
python3.12 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
mkdir -p reports
'''
}
}
stage('Unit Tests (Parallel)') {
parallel {
stage('Unit Batch 1') {
steps {
sh '''
. venv/bin/activate
pytest tests/unit -n auto \
--junitxml=reports/unit1.xml \
--cov=app --cov-report=xml:reports/coverage1.xml
'''
}
}
stage('Unit Batch 2') {
steps {
sh '''
. venv/bin/activate
pytest tests/unit -n auto \
--junitxml=reports/unit2.xml \
--cov=app --cov-report=xml:reports/coverage2.xml
'''
}
}
}
post {
always {
junit 'reports/unit*.xml'
publishCoverage adapters: [coberturaAdapter('reports/coverage*.xml')]
}
}
}
stage('Integration Tests') {
steps {
withVault(configuration: vaultConfig(), vaultSecrets: vaultSecrets()) {
sh '''
. venv/bin/activate
export API_KEY=$API_KEY
export ENV=staging
pytest tests/integration \
--junitxml=reports/integration.xml
'''
}
}
post {
always {
junit 'reports/integration.xml'
}
}
}
stage('E2E Tests (Selenium Grid)') {
steps {
withVault(configuration: vaultConfig(), vaultSecrets: vaultSecrets()) {
sh '''
. venv/bin/activate
export API_KEY=$API_KEY
export SELENIUM_GRID_URL=$SELENIUM_GRID
# Start Flask app in background
nohup python app.py &
FLASK_PID=$!
# Give Flask a few seconds to start
sleep 5
pytest tests/e2e/test_selenium.py \
--junitxml=reports/e2e_selenium.xml
kill $FLASK_PID
'''
}
}
post {
always {
junit 'reports/e2e_selenium.xml'
}
}
}
stage('Upload Reports to S3') {
steps {
withAWS(region: "${AWS_REGION}", credentials: 'aws-jenkins-credentials') {
sh '''
aws s3 cp reports/ \
s3://${S3_BUCKET}/${SERVICE_NAME}/${BUILD_NUMBER}/ \
--recursive
'''
}
}
}
}
}