Add jenkinsfile

This commit is contained in:
Duvan Rondon 2025-02-24 15:17:52 -05:00
parent 2aee42841e
commit 6a13eb31e0
2 changed files with 47 additions and 20 deletions

View File

@ -25,40 +25,62 @@ pipeline {
} }
} }
stage('Deploy to Cloud Run') { stage('Deploy to Cloud Run Firmador') {
steps { steps {
script { script {
// Ejecuta el comando capturando stdout + stderr // 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() 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 // Busca la URL en la salida usando expresión regular
echo "Salida completa de gcloud:\n${output ?: '[VACÍO]'}" def cloudRunUrlMatch = output =~ /URL:\s+(https:\/\/[^\s]+)/
// Busca la URL en la salida usando expresión regular if (cloudRunUrlMatch) {
def cloudRunUrlMatch = output =~ /URL:\s+(https:\/\/[^\s]+)/ def cloudRunUrl = cloudRunUrlMatch[0][1] // Captura la URL
env.CLOUD_RUN_FIRMADOR = cloudRunUrl
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."
}
} }
}
} }
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') { stage('Allow allUsers') {
steps { steps {
sh ''' 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' sh 'gcloud auth revoke $CLIENT_EMAIL'
} }
} }
} }

View File

@ -25,4 +25,9 @@ spec:
failureThreshold: 1 failureThreshold: 1
tcpSocket: tcpSocket:
port: 8440 port: 8440
env:
- name: SERVICIO_LOTES
value: SERVICE_LOTES_URL
- name: SERVICIO_NEST
value: SERVICE_NEST_URL