From acd3f5c8f489a40053af3558ccb9948f8b7015e7 Mon Sep 17 00:00:00 2001 From: ValentinoSanchez00 Date: Fri, 27 Dec 2024 09:50:55 +0100 Subject: [PATCH] cambiando todo otra vez de red --- jenkins/subir-Dockerfile | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/jenkins/subir-Dockerfile b/jenkins/subir-Dockerfile index 6ab2225..98e38b2 100644 --- a/jenkins/subir-Dockerfile +++ b/jenkins/subir-Dockerfile @@ -1,29 +1,30 @@ pipeline { - agent any + agent { + kubernetes { + label 'docker' // Usamos el agente con Docker preinstalado + defaultContainer 'docker' + } + } environment { APIKEY = credentials('IBM_CLOUD_API_KEY_VSANCHEZ') // Define la credencial en Jenkins previamente } parameters { string(name: 'MICROSERVICE', defaultValue: 'frontend', description: 'Nombre del microservicio (frontend/backend)') + string(name: 'ENVIRONMENT', defaultValue: 'develop', description: 'Ambiente de despliegue (develop/production)') } stages { - stage('Determinar Ambiente') { + stage('Mostrar ConfiguraciĆ³n') { steps { - script { - if (env.BRANCH_NAME == 'main') { - env.ENVIRONMENT = 'production' - } else { - env.ENVIRONMENT = 'develop' - } - echo "Ambiente configurado: ${env.ENVIRONMENT}" - } + echo "ConfiguraciĆ³n elegida:" + echo "Microservicio: ${params.MICROSERVICE}" + echo "Ambiente: ${params.ENVIRONMENT}" } } stage('Test Frontend') { when { allOf { expression { params.MICROSERVICE == 'frontend' } - branch 'main' + expression { params.ENVIRONMENT == 'production' } } } steps { @@ -59,10 +60,11 @@ pipeline { stage('Instalar Herramientas') { steps { sh """ - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + curl -sL https://aka.ms/InstallAzureCLIDeb | bash curl -fsSL https://clis.cloud.ibm.com/install/linux | sh ibmcloud plugin install container-registry -r 'IBM Cloud' ibmcloud plugin install container-service -r 'IBM Cloud' + apt update && apt upgrade -y """ } } @@ -72,6 +74,7 @@ pipeline { ibmcloud login --apikey ${APIKEY} -r eu-gb ibmcloud target -g Stemdo_Sandbox ibmcloud cr login + ibmcloud cr namespace-add cr-vsanchez """ } } @@ -95,20 +98,20 @@ pipeline { } stage('Construir Imagen') { steps { - sh "docker build -t imagen-proyecto-${params.MICROSERVICE}-${env.ENVIRONMENT} ." + sh "docker build -t imagen-proyecto-${params.MICROSERVICE}-${params.ENVIRONMENT} ." } } stage('Taggear Imagen') { steps { sh """ - docker tag imagen-proyecto-${params.MICROSERVICE}-${env.ENVIRONMENT} uk.icr.io/cr-vsanchez/imagen-proyecto-${params.MICROSERVICE}-${env.ENVIRONMENT}:${env.VERSION} + docker tag imagen-proyecto-${params.MICROSERVICE}-${params.ENVIRONMENT} uk.icr.io/cr-vsanchez/imagen-proyecto-${params.MICROSERVICE}-${params.ENVIRONMENT}:${env.VERSION} """ } } stage('Pushear Imagen') { steps { sh """ - docker push uk.icr.io/cr-vsanchez/imagen-proyecto-${params.MICROSERVICE}-${env.ENVIRONMENT}:${env.VERSION} + docker push uk.icr.io/cr-vsanchez/imagen-proyecto-${params.MICROSERVICE}-${params.ENVIRONMENT}:${env.VERSION} """ } }