CBII-CloudRun/Jenkinsfile copy
2025-02-24 15:17:52 -05:00

95 lines
2.5 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 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()
// 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('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-apigateway-jenkins --region='us-central1' --member='allUsers' --role='roles/run.invoker'
'''
}
}
}
post {
always {
sh 'gcloud auth revoke $CLIENT_EMAIL'
}
}
}