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') CLOUD_RUN_FIRMADOR = 'http://localhost:8113' } stages { stage('Clonar Repositorio') { steps { git credentialsId: 'token_gitea', url: 'https://gitea.grupoconsiti.com/duvan_andres/prueba.git', branch: 'main' } } stage('Envs Project') { steps { sh ''' sed -i "s|CLOUDSDK_CORE_PROJECT|${CLOUDSDK_CORE_PROJECT}|g" **.yml ''' } } stage('Authenticate') { steps { withCredentials([file(credentialsId: 'gcloud-creds', variable: 'GCLOUD_CREDS')]) { sh 'gcloud auth activate-service-account --key-file="$GCLOUD_CREDS"' } } } 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 { def outputNest = sh(script: "gcloud run services replace service-nest.yml --platform=managed --region=${REGION} 2>&1", returnStdout: true).trim() def outputSpring = sh(script: "gcloud run services replace service-spring.yml --platform=managed --region=${REGION} 2>&1", returnStdout: true).trim() def cloudRunUrlMatchNest = outputNest =~ /URL:\s+(https:\/\/[^\s]+)/ def cloudRunUrlMatchLotes = outputSpring =~ /URL:\s+(https:\/\/[^\s]+)/ if (cloudRunUrlMatchNest) { env.CLOUD_RUN_NEST = cloudRunUrlMatchNest[0][1] } if (cloudRunUrlMatchLotes) { env.CLOUD_RUN_LOTES = cloudRunUrlMatchLotes[0][1] } } } } stage('Envs about Nest and Spring') { steps { sh ''' sed -i "s|SERVICE_NEST_URL|${CLOUD_RUN_NEST}|g" **.yml sed -i "s|SERVICE_LOTES_URL|${CLOUD_RUN_LOTES}|g" **.yml cat service-api-gateway.yml ''' } } stage('Deploy Api Gateway') { steps { sh ''' gcloud run services replace service-api-gateway.yml --platform='managed' --region='us-central1' ''' } } 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' } } }