72 lines
2.0 KiB
Plaintext
72 lines
2.0 KiB
Plaintext
pipeline {
|
|
agent any
|
|
environment {
|
|
CLOUDSDK_CORE_PROJECT = 'siman-448015'
|
|
REGION = "us-central1"
|
|
CLIENT_EMAIL = 'svfe-api-firmador@siman-448015.iam.gserviceaccount.com'
|
|
GCLOUD_CREDS = credentials('gcloud-creds')
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Clonar Repositorio') {
|
|
steps {
|
|
git credentialsId: 'token_gitea',
|
|
url: 'https://gitea.grupoconsiti.com/duvan_andres/prueba.git',
|
|
branch: 'main'
|
|
}
|
|
}
|
|
|
|
stage('Authenticate') {
|
|
steps {
|
|
sh '''
|
|
gcloud auth activate-service-account --key-file="$GCLOUD_CREDS"
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('Deploy to Cloud Run') {
|
|
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()
|
|
|
|
// 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]+)/
|
|
|
|
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('Allow allUsers') {
|
|
steps {
|
|
sh '''
|
|
gcloud run services add-iam-policy-binding cbii-jenkins --region='us-central1' --member='allUsers' --role='roles/run.invoker'
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
sh 'gcloud auth revoke $CLIENT_EMAIL'
|
|
}
|
|
}
|
|
} |