Updated the Jenkinsfile
This commit is contained in:
parent
466e51c703
commit
e45bc2bd3e
71
expenses_manager/Jenkinsfile
vendored
71
expenses_manager/Jenkinsfile
vendored
@ -1,39 +1,49 @@
|
|||||||
pipeline{
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
DEBUG = 'True'
|
// settings.py demands SECRET_KEY unless DEBUG is exactly "True".
|
||||||
DJANGO_SECRET_KEY = 'test-secret-key-for-ci'
|
// A throwaway value lets CI run with DEBUG unset — that is, False, as
|
||||||
DJANGO_SETTINGS_MODULE = "expenses_manager.settings"
|
// in production — instead of falling back to the insecure dev key.
|
||||||
PYTHONUNBUFFERED = "1"
|
SECRET_KEY = 'ci-only-value-never-used-in-production'
|
||||||
|
DJANGO_SETTINGS_MODULE = 'expenses_manager.settings'
|
||||||
|
PYTHONUNBUFFERED = '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '30'))
|
||||||
|
timeout(time: 20, unit: 'MINUTES')
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
|
||||||
steps {
|
|
||||||
checkout scm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Setup Python') {
|
stage('Setup Python') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
cd expenses_manager
|
cd expenses_manager
|
||||||
python --version
|
python --version
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
. venv/bin/activate
|
venv/bin/pip install --upgrade pip
|
||||||
pip install --upgrade pip
|
venv/bin/pip install -r requirements.txt
|
||||||
pip install -r requirements.txt
|
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Catches models changed without generating the migration. Exactly the
|
||||||
|
// failure mode that reached production as a 500 on 2026-09-29.
|
||||||
|
stage('Check migrations') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
cd expenses_manager
|
||||||
|
venv/bin/python manage.py makemigrations --check --dry-run
|
||||||
|
'''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Run tests') {
|
stage('Run tests') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
cd expenses_manager
|
cd expenses_manager
|
||||||
. venv/bin/activate
|
venv/bin/pytest --cov --junitxml=junit.xml
|
||||||
venv/bin/pytest --cov
|
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,10 +51,33 @@ pipeline{
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
echo 'Pipeline finished.'
|
// allowEmptyResults: false is deliberate. A build where pytest died
|
||||||
|
// before collecting anything produces no XML, and that must fail
|
||||||
|
// rather than pass quietly — as happened for months in 2026.
|
||||||
|
junit allowEmptyResults: false, testResults: 'expenses_manager/junit.xml'
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo 'Tests failed.'
|
notifyTelegram("❌ FALLO")
|
||||||
|
}
|
||||||
|
fixed {
|
||||||
|
notifyTelegram("✅ Recuperado")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sends a one-line build summary to Telegram. Credentials are read from the
|
||||||
|
// Jenkins store so the token never lives in the repository.
|
||||||
|
void notifyTelegram(String status) {
|
||||||
|
withCredentials([
|
||||||
|
string(credentialsId: 'telegram-bot-token', variable: 'TG_TOKEN'),
|
||||||
|
string(credentialsId: 'telegram-chat-id', variable: 'TG_CHAT')
|
||||||
|
]) {
|
||||||
|
sh """
|
||||||
|
curl -s -X POST "https://api.telegram.org/bot\${TG_TOKEN}/sendMessage" \
|
||||||
|
--data-urlencode "chat_id=\${TG_CHAT}" \
|
||||||
|
--data-urlencode "text=${status} ${env.JOB_NAME} #${env.BUILD_NUMBER}
|
||||||
|
Rama: ${env.BRANCH_NAME ?: 'main'}
|
||||||
|
${env.BUILD_URL}" > /dev/null
|
||||||
|
"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user