Sfoglia il codice sorgente

Pongo Jenkinsfile como los demás

Celestino Rey 6 mesi fa
parent
commit
698d406e3e
1 ha cambiato i file con 18 aggiunte e 48 eliminazioni
  1. 18 48
      Jenkinsfile

+ 18 - 48
Jenkinsfile

@@ -23,7 +23,6 @@ pipeline {
     booleanParam(name: 'borraclaims', description: 'Borra PVC', defaultValue: false)
     booleanParam(name: 'namespace', description: 'Crea namespace', defaultValue: false)
     booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
-    booleanParam(name: 'helm', description: 'Instala helm', defaultValue: false)
     booleanParam(name: 'creadb', description: 'Crea el objeto para crear la DB en el cúster', defaultValue: false)
     booleanParam(name: 'borradb', description: 'Borra el objeto que creó la DB, no la DB', defaultValue: false)
   }
@@ -37,12 +36,9 @@ pipeline {
         echo "Creando las PVC..." 
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
-          sh """#!/bin/bash
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/pvc-${NOMBRE_APP}.yaml
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/pvc-static.yaml
-
-            kubectl create -f K8S/pvc-${NOMBRE_APP}.yaml
-            kubectl create -f K8S/pvc-static.yaml
+	  sh """#!/bin/bash
+	    cat K8S/pvc-${NOMBRE_APP}.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
+	    cat K8S/pvc-static.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
             """
           }
         }
@@ -57,14 +53,9 @@ pipeline {
         echo "Borrando las PVC..." 
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
-          sh """#!/bin/bash
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/pvc-${NOMBRE_APP}.yaml
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/pvc-static.yaml
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/patchPVC.sh
-
-            sh K8S/patchPVC.sh||true
-            kubectl delete -f K8S/pvc-${NOMBRE_APP}.yaml
-            kubectl delete -f K8S/pvc-static.yaml
+	  sh """#!/bin/bash
+	    cat K8S/pvc-${NOMBRE_APP}.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
+	    cat K8S/pvc-static.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
             """
           }
         }
@@ -80,7 +71,7 @@ pipeline {
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
 	  sh """#!/bin/bash
-	    kubectl create -f K8S/peritajes-db.yaml 
+	    kubectl create -f K8S/${NOMBRE_APP}-db.yaml 
             """
           }
         }
@@ -96,7 +87,7 @@ pipeline {
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
 	  sh """#!/bin/bash
-	    kubectl delete -f K8S/peritajes-db.yaml 
+	    kubectl delete -f K8S/${NOMBRE_APP}-db.yaml 
             """
           }
         }
@@ -115,11 +106,13 @@ pipeline {
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-deployment.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-ingress.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/reg-secret.yaml
+            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/secreto-db.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/env-prod-configmap.yaml
 
             kubectl delete -f K8S/${NOMBRE_APP}-deployment.yaml||true
             kubectl delete -f K8S/${NOMBRE_APP}-ingress.yaml||true
 
+            kubectl delete -f K8S/secreto-db.yaml||true
             kubectl delete -f K8S/reg-secret.yaml||true
             kubectl delete -f K8S/env-prod-configmap.yaml||true 
           """
@@ -136,7 +129,9 @@ pipeline {
         echo "Borrando namespace..." 
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
-            sh 'kubectl delete -f K8S/namespace.yaml||true'
+	  sh """#!/bin/bash
+	    cat K8S/namespace.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
+            """
           }
         }
       }      
@@ -150,9 +145,8 @@ pipeline {
         echo "Creando namespace..." 
         container('kubectl') {
           withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
-          sh """#!/bin/bash
-            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/namespace.yaml
-            kubectl create -f K8S/namespace.yaml
+	  sh """#!/bin/bash
+	    cat K8S/namespace.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
             """
           }
         }
@@ -189,14 +183,16 @@ pipeline {
       steps {
         echo "Creando todo..." 
         container('kubectl') {
-          withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {           
+          withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
           sh """#!/bin/bash
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-deployment.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-ingress.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/reg-secret.yaml
+            sed -i 's|<NS>|"${NAMESPACE}"|' K8S/secreto-db.yaml
             sed -i 's|<NS>|"${NAMESPACE}"|' K8S/env-prod-configmap.yaml
 
             kubectl create -f K8S/reg-secret.yaml||true
+            kubectl create -f K8S/secreto-db.yaml||true
             kubectl apply -f K8S/env-prod-configmap.yaml
 
             sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml
@@ -216,7 +212,6 @@ pipeline {
           expression { !params.borranamespace } 
           expression { !params.claims }
           expression { !params.borraclaims }
-          expression { !params.install }
         }
       }
       steps {
@@ -233,30 +228,6 @@ pipeline {
         }
       }
     }   
-
-    stage('Instala Helm Chart') {
-      when {
-        allOf {
-          expression { !params.clean }
-          expression { !params.namespace }
-          expression { !params.borranamespace } 
-          expression { !params.claims }
-          expression { !params.borraclaims }
-          expression { !params.install }
-          expression { params.helm }
-        }
-      }
-      steps {
-        echo "Instalando el helm chart" 
-        container('kubectl') {
-          withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
-          sh """#!/bin/bash
-            helm upgrade finanzas finanzas --namespace finanzas --set=image.tag=${BUILD_NUMBER}
-            """
-          }
-        }
-      }
-    }
   }
   
   post {
@@ -289,4 +260,3 @@ pipeline {
     }
   }
 }
-