Compare commits

..

No commits in common. "29bb1c5d248ea12e3c9109293249166409616e5f" and "7cf8d8ce07b086edc1b04582e40917b387b7d506" have entirely different histories.

View File

@ -1,40 +1,29 @@
pipeline { pipeline{
agent any agent any
environment { environment {
// settings.py demands SECRET_KEY unless DEBUG is exactly "True". DEBUG = 'True'
// A throwaway value lets CI run with DEBUG unset — that is, False, as DJANGO_SECRET_KEY = 'test-secret-key-for-ci'
// in production — instead of falling back to the insecure dev key. DJANGO_SETTINGS_MODULE = "expenses_manager.settings"
SECRET_KEY = 'ci-only-value-never-used-in-production' PYTHONUNBUFFERED = "1"
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/pip install --upgrade pip . venv/bin/activate
venv/bin/pip install -r requirements.txt pip install --upgrade pip
''' 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
''' '''
} }
} }
@ -43,7 +32,8 @@ pipeline {
steps { steps {
sh ''' sh '''
cd expenses_manager cd expenses_manager
venv/bin/pytest --cov --junitxml=junit.xml . venv/bin/activate
venv/bin/pytest --cov
''' '''
} }
} }
@ -51,33 +41,10 @@ pipeline {
post { post {
always { always {
// allowEmptyResults: false is deliberate. A build where pytest died echo 'Pipeline finished.'
// 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 {
notifyTelegram("❌ FALLO") echo 'Tests failed.'
}
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
"""
}
}