From 6a13eb31e0652f4b47200f1ccdbf862a6e48ca0b Mon Sep 17 00:00:00 2001 From: Duvan Rondon Date: Mon, 24 Feb 2025 15:17:52 -0500 Subject: [PATCH] Add jenkinsfile --- Jenkinsfile copy | 62 ++++++++++++++++++++++++++++------------- service-api-gateway.yml | 5 ++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile copy b/Jenkinsfile copy index 9d9f038..cebee3c 100644 --- a/Jenkinsfile copy +++ b/Jenkinsfile copy @@ -25,40 +25,62 @@ pipeline { } } - stage('Deploy to Cloud Run') { + stage('Deploy to Cloud Run Firmador') { steps { script { - // Ejecuta el comando capturando stdout + stderr - def output = sh(script: "gcloud run services replace service-firmador.yml --platform=managed --region=${REGION} 2>&1", returnStdout: true).trim() + // Ejecuta el comando capturando stdout + stderr + def output = sh(script: "gcloud run services replace service-firmador.yml --platform=managed --region=${REGION} 2>&1", returnStdout: true).trim() - // Verifica si la salida realmente tiene contenido - echo "Salida completa de gcloud:\n${output ?: '[VACÍO]'}" + // Busca la URL en la salida usando expresión regular + def cloudRunUrlMatch = output =~ /URL:\s+(https:\/\/[^\s]+)/ - // Busca la URL en la salida usando expresión regular - def cloudRunUrlMatch = output =~ /URL:\s+(https:\/\/[^\s]+)/ - - if (cloudRunUrlMatch) { - def cloudRunUrl = cloudRunUrlMatch[0][1] // Captura la URL - echo "✅ Cloud Run Service URL: ${cloudRunUrl}" - env.CLOUD_RUN_URL = cloudRunUrl - - // Reemplazo correcto en archivos YAML - sh "sed -i 's|SERVICE_FIRMADOR_URL|${env.CLOUD_RUN_URL}|g' **.yml" - } else { - error "⚠️ No se pudo extraer la URL de Cloud Run. Revisar la salida de gcloud." - } + if (cloudRunUrlMatch) { + def cloudRunUrl = cloudRunUrlMatch[0][1] // Captura la URL + env.CLOUD_RUN_FIRMADOR = cloudRunUrl + } } + } } + stage('Envs about Firmador') { + steps { + sh ''' + sed -i "s|SERVICE_FIRMADOR_URL|${CLOUD_RUN_FIRMADOR}|g" **.yml + cat service-nest.yml + ''' + } + } + stage('Deploy to Cloud Run Nest and Spring') { + steps { + script { + // Ejecuta el comando capturando stdout + stderr + def output = sh(script: "gcloud run services replace service-firmador.yml --platform=managed --region=${REGION} 2>&1", returnStdout: true).trim() + // Busca la URL en la salida usando expresión regular + def cloudRunUrlMatch = output =~ /URL:\s+(https:\/\/[^\s]+)/ + if (cloudRunUrlMatch) { + def cloudRunUrl = cloudRunUrlMatch[0][1] // Captura la URL + env.CLOUD_RUN_FIRMADOR = cloudRunUrl + } + } + } + } + + stage('Envs about Firmador') { + steps { + sh ''' + sed -i "s|SERVICE_FIRMADOR_URL|${CLOUD_RUN_FIRMADOR}|g" **.yml + cat service-nest.yml + ''' + } } stage('Allow allUsers') { steps { sh ''' - gcloud run services add-iam-policy-binding cbii-jenkins --region='us-central1' --member='allUsers' --role='roles/run.invoker' + gcloud run services add-iam-policy-binding cbii-apigateway-jenkins --region='us-central1' --member='allUsers' --role='roles/run.invoker' ''' } } @@ -69,4 +91,4 @@ pipeline { sh 'gcloud auth revoke $CLIENT_EMAIL' } } -} \ No newline at end of file +} diff --git a/service-api-gateway.yml b/service-api-gateway.yml index 6a3400b..9c25465 100644 --- a/service-api-gateway.yml +++ b/service-api-gateway.yml @@ -25,4 +25,9 @@ spec: failureThreshold: 1 tcpSocket: port: 8440 + env: + - name: SERVICIO_LOTES + value: SERVICE_LOTES_URL + - name: SERVICIO_NEST + value: SERVICE_NEST_URL