Add jenkinsfile

This commit is contained in:
Duvan Rondon 2025-02-21 22:58:35 -05:00
parent 77bda1a0e5
commit 2aee42841e
4 changed files with 133 additions and 2 deletions

59
Jenkinsfile vendored Normal file
View File

@ -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'
}
}
}

72
Jenkinsfile copy Normal file
View File

@ -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'
}
}
}

View File

@ -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

View File

@ -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