From 2aee42841e0513e6cef59c826f8cd8a402011fef Mon Sep 17 00:00:00 2001 From: Duvan Rondon Date: Fri, 21 Feb 2025 22:58:35 -0500 Subject: [PATCH] Add jenkinsfile --- Jenkinsfile | 59 +++++++++++++++++++++++++++++++++++++ Jenkinsfile copy | 72 ++++++++++++++++++++++++++++++++++++++++++++++ service-nest.yml | 2 +- service-spring.yml | 2 +- 4 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 Jenkinsfile create mode 100644 Jenkinsfile copy diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..5bfb5ee --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,59 @@ +pipeline { + agent any + environment { + CLOUDSDK_CORE_PROJECT = 'siman-448015' + 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('Verify version') { + steps { + sh ''' + gcloud version + ls -la + ''' + } + } + + stage('Authenticate') { + steps { + sh ''' + gcloud auth activate-service-account --key-file="$GCLOUD_CREDS" + ''' + } + } + + stage('Install service') { + steps { + sh ''' + gcloud projects get-iam-policy siman-448015 --flatten="bindings[].members" --format="table(bindings.role, bindings.members)" | grep svfe-api-firmador + gcloud run services replace service.yml --platform='managed' --region='us-central1' + ''' + } + } + + 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' + } + } +} \ No newline at end of file diff --git a/Jenkinsfile copy b/Jenkinsfile copy new file mode 100644 index 0000000..9d9f038 --- /dev/null +++ b/Jenkinsfile copy @@ -0,0 +1,72 @@ +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' + } + } +} \ No newline at end of file diff --git a/service-nest.yml b/service-nest.yml index 721ff97..e401889 100644 --- a/service-nest.yml +++ b/service-nest.yml @@ -27,7 +27,7 @@ spec: port: 3000 env: - name: FIRMADOR_URL - value: ${FIRMADOR_URL:-http://localhost:8113} + value: SERVICE_FIRMADOR_URL - name: SPACES_ENDPOINT value: https://sfo3.digitaloceanspaces.com - name: DATABASE_URL diff --git a/service-spring.yml b/service-spring.yml index 1e94cf9..1e1dd07 100644 --- a/service-spring.yml +++ b/service-spring.yml @@ -27,7 +27,7 @@ spec: port: 8080 env: - name: FIRMADOR_URL - value: http://localhost:8113 + value: SERVICE_FIRMADOR_URL - name: SERVER_PORT value: '8080' - name: JWT_SECRET