Compare commits

..

3 Commits

Author SHA1 Message Date
0ac0a859b9 Merge pull request 'dev' (#24) from dev into master
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
Reviewed-on: #24
2026-04-14 21:52:57 +00:00
02aca6a2a6 Merge pull request 'Update Jenkinsfile' (#23) from pre-dev into dev
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
DEPLOY_MULTI_BRACH/pipeline/pr-master This commit looks good
Reviewed-on: #23
2026-04-14 21:48:28 +00:00
minguezsanzjuanjose
4a4d0940b3 Update Jenkinsfile
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
2026-04-14 23:47:24 +02:00

View File

@@ -5,19 +5,19 @@ pipeline {
stage('Configurar Entorno') { stage('Configurar Entorno') {
steps { steps {
script { script {
// Seleccionamos ID de credencial y config según la rama // Selección de configuración según la rama
if (env.BRANCH_NAME == 'master') { if (env.BRANCH_NAME == 'master') {
env.PROJECT_NAME = "django_master" env.PROJECT_NAME = "django_master"
env.APP_CONTAINER_NAME = "django_app_master" env.APP_CONTAINER_NAME = "django_app_master"
env.PORT = "8001" env.PORT = "8001"
env.DEBUG_MODE = "0" env.DEBUG_MODE = "0"
env.ENV_CREDENTIAL_ID = "2" // Tu ID para master env.ENV_CREDENTIAL_ID = "2"
} else { } else if (env.BRANCH_NAME == 'dev') {
env.PROJECT_NAME = "django_dev" env.PROJECT_NAME = "django_dev"
env.APP_CONTAINER_NAME = "django_app_dev" env.APP_CONTAINER_NAME = "django_app_dev"
env.PORT = "8000" env.PORT = "8000"
env.DEBUG_MODE = "1" env.DEBUG_MODE = "1"
env.ENV_CREDENTIAL_ID = "1" // Tu ID para dev env.ENV_CREDENTIAL_ID = "1"
} }
} }
} }
@@ -26,19 +26,23 @@ pipeline {
stage('Fase Final: Containerización') { stage('Fase Final: Containerización') {
when { anyOf { branch 'dev'; branch 'master' } } when { anyOf { branch 'dev'; branch 'master' } }
steps { steps {
// Bloque mágico: extrae el archivo .env de la bóveda de Jenkins
withCredentials([file(credentialsId: env.ENV_CREDENTIAL_ID, variable: 'SECRET_ENV')]) { withCredentials([file(credentialsId: env.ENV_CREDENTIAL_ID, variable: 'SECRET_ENV')]) {
sh """ sh """
echo "Copiando configuración segura..." echo "--> Preparando configuración segura..."
cp \$SECRET_ENV deployments/.env cp \$SECRET_ENV deployments/.env
echo "🚀 DESPLEGANDO: ${env.APP_CONTAINER_NAME} en puerto ${env.PORT}" echo "--> 🚀 DESPLEGANDO PROYECTO: ${env.PROJECT_NAME}"
export APP_CONTAINER_NAME=${env.APP_CONTAINER_NAME} # 1. Limpieza de contenedores previos para evitar conflictos de nombres
export PORT=${env.PORT} docker compose -p ${env.PROJECT_NAME} -f deployments/docker-compose.yml down --remove-orphans
export DEBUG_MODE=${env.DEBUG_MODE}
docker compose -p ${env.PROJECT_NAME} -f deployments/docker-compose.yml up -d --build web # 2. Despliegue forzando la lectura del archivo .env específico
# CRÍTICO: --env-file asegura que DATABASE_EXPOSE_PORT se lea correctamente
docker compose \
-p ${env.PROJECT_NAME} \
-f deployments/docker-compose.yml \
--env-file deployments/.env \
up -d --build web
""" """
} }
} }
@@ -47,12 +51,11 @@ pipeline {
post { post {
success { success {
echo "✅ Despliegue completado con éxito." echo "✅ Despliegue de ${env.BRANCH_NAME} completado con éxito."
// Limpieza preventiva: borramos el .env físico después del despliegue
sh "rm -f deployments/.env" sh "rm -f deployments/.env"
} }
failure { failure {
echo "❌ Error en el despliegue. Revisa los logs." echo "❌ Error en el despliegue de ${env.BRANCH_NAME}."
sh "rm -f deployments/.env" sh "rm -f deployments/.env"
} }
} }