pipeline { agent none options { disableConcurrentBuilds() timestamps() } parameters { string( name: 'JENKINS_BASE_URL', defaultValue: 'https://openbokeron.org/jenkins', description: 'Base URL del Jenkins objetivo' ) string( name: 'JENKINS_JOB_NAME', defaultValue: 'CD', description: 'Nombre del job que se consulta en Jenkins' ) string( name: 'VITE_API_BASE', defaultValue: '/taller/api', description: 'Base path/API para el frontend (build time)' ) } environment { NODE_OPTIONS = '--max_old_space_size=2048' APP_VERSION = "1.0.${BUILD_NUMBER}" DOCKER_BUILDKIT = '1' JENKINS_BASE_URL = "${params.JENKINS_BASE_URL}" JENKINS_JOB_NAME = "${params.JENKINS_JOB_NAME}" VITE_API_BASE = "${params.VITE_API_BASE}" PYTHONDONTWRITEBYTECODE = 1 } triggers { gitea( branchFilterType: 'Include', branchFilter: 'main', secret: '' ) } stages { /* ========================= TESTS ========================= */ stage('Backend: test (main)') { agent { docker { image 'python:3.11-slim' args '-u root' } } steps { dir('backend') { sh ''' set -e python -m venv .venv . .venv/bin/activate pip install --upgrade pip pip install -r requirements-dev.txt pytest ''' } } } /* ========================= DOCKER BUILD ========================= */ stage('Docker: build images') { agent any steps { script { env.COMMIT_SHORT = sh( script: "git rev-parse --short HEAD", returnStdout: true ).trim() env.COMMIT_AUTHOR = sh( script: "git show -s --format=%an HEAD", returnStdout: true ).trim() } sh ''' set -e docker build \ --build-arg APP_VERSION=${APP_VERSION} \ --build-arg GIT_COMMIT=${COMMIT_SHORT} \ --build-arg COMMIT_AUTHOR="${COMMIT_AUTHOR}" \ --build-arg BUILD_NUMBER=${BUILD_NUMBER} \ -t cafeteria-backend:${APP_VERSION} \ ./backend docker build \ --build-arg VITE_API_BASE=${VITE_API_BASE} \ -t cafeteria-frontend:${APP_VERSION} \ ./frontend ''' } } /* ========================= DEPLOY ========================= */ stage('Deploy (docker compose)') { agent any steps { withCredentials([ usernamePassword( credentialsId: 'jenkins-api-token', usernameVariable: 'JENKINS_USER', passwordVariable: 'JENKINS_TOKEN' ) ]) { sh ''' set -e echo "Deploying ${APP_VERSION}" BACKEND_TAG=${APP_VERSION} FRONTEND_TAG=${APP_VERSION} docker compose up -d ''' } } } stage('Cleanup') { agent any steps { cleanWs() } } } }