From f95aa23bac504a625c808e8aff85fb0c39732458 Mon Sep 17 00:00:00 2001 From: hyun123 Date: Thu, 10 Oct 2024 11:05:53 +0900 Subject: [PATCH] source update --- .../kubernetes_helm_install_pipeline.xml | 41 +++++++++++++------ .../vm_application_install_pipeline.xml | 15 +++++++ .../vm_application_uninstall_pipeline.xml | 15 +++++++ .../cbtumblebug/dto/K8sClusterResponse.java | 3 ++ .../kubernetes_helm_install_pipeline.xml | 41 +++++++++++++------ .../vm_application_install_pipeline.xml | 15 +++++++ .../vm_application_uninstall_pipeline.xml | 15 +++++++ 7 files changed, 119 insertions(+), 26 deletions(-) diff --git a/bin/main/jenkins/kubernetes_helm_install_pipeline.xml b/bin/main/jenkins/kubernetes_helm_install_pipeline.xml index d2be9a5..d63e97c 100644 --- a/bin/main/jenkins/kubernetes_helm_install_pipeline.xml +++ b/bin/main/jenkins/kubernetes_helm_install_pipeline.xml @@ -59,30 +59,34 @@ pipeline { environment { PATH = "${env.HOME}/bin:${env.PATH}" + HELM_INSTALLED = false + KUBECTL_INSTALLED = false } stages { - stage('Install kubectl and Helm') { + stage('Check and Install kubectl and Helm') { steps { script { - // Install kubectl - sh ''' - if ! command -v kubectl &> /dev/null; then + // Check and install kubectl + if (sh(script: "command -v kubectl", returnStatus: true) != 0) { + sh ''' curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl mkdir -p $HOME/bin mv kubectl $HOME/bin/ - fi - kubectl version --client - ''' + ''' + env.KUBECTL_INSTALLED = true + } + sh "kubectl version --client" - // Install Helm (if not already installed) - sh ''' - if ! command -v helm &> /dev/null; then + // Check and install Helm + if (sh(script: "command -v helm", returnStatus: true) != 0) { + sh ''' curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash - fi - helm version - ''' + ''' + env.HELM_INSTALLED = true + } + sh "helm version" } } } @@ -193,6 +197,17 @@ pipeline { always { sh "rm -f ${WORKSPACE}/kubeconfig" echo "Removed kubeconfig file" + + script { + if (env.KUBECTL_INSTALLED == 'true') { + sh "rm -f $HOME/bin/kubectl" + echo "Removed kubectl" + } + if (env.HELM_INSTALLED == 'true') { + sh "rm -f /usr/local/bin/helm" + echo "Removed Helm" + } + } } success { echo "Helm charts installation and verification completed successfully!" diff --git a/bin/main/jenkins/vm_application_install_pipeline.xml b/bin/main/jenkins/vm_application_install_pipeline.xml index f3d92f2..5df6831 100644 --- a/bin/main/jenkins/vm_application_install_pipeline.xml +++ b/bin/main/jenkins/vm_application_install_pipeline.xml @@ -265,6 +265,21 @@ echo ========================================================================== } } } + + post { + always { + echo '>>>>>POST: Cleaning up PEM file' + script { + if (env.PEM_FILE_PATH) { + echo "Deleting PEM file: ${env.PEM_FILE_PATH}" + sh "rm -f ${env.PEM_FILE_PATH}" + echo "PEM file deleted successfully" + } else { + echo "No PEM file to delete" + } + } + } + } } diff --git a/bin/main/jenkins/vm_application_uninstall_pipeline.xml b/bin/main/jenkins/vm_application_uninstall_pipeline.xml index a2f28df..f35519f 100644 --- a/bin/main/jenkins/vm_application_uninstall_pipeline.xml +++ b/bin/main/jenkins/vm_application_uninstall_pipeline.xml @@ -180,6 +180,21 @@ echo ========================================================================== } } } + + post { + always { + echo '>>>>>POST: Cleaning up PEM file' + script { + if (env.PEM_FILE_PATH) { + echo "Deleting PEM file: ${env.PEM_FILE_PATH}" + sh "rm -f ${env.PEM_FILE_PATH}" + echo "PEM file deleted successfully" + } else { + echo "No PEM file to delete" + } + } + } + } } ]]> diff --git a/src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/K8sClusterResponse.java b/src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/K8sClusterResponse.java index 4be853d..0c93835 100644 --- a/src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/K8sClusterResponse.java +++ b/src/main/java/kr/co/mcmp/ape/cbtumblebug/dto/K8sClusterResponse.java @@ -2,6 +2,8 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -10,5 +12,6 @@ @NoArgsConstructor @AllArgsConstructor public class K8sClusterResponse { + @JsonProperty("K8sClusterInfo") private List k8sClusterInfo; } \ No newline at end of file diff --git a/src/main/resources/jenkins/kubernetes_helm_install_pipeline.xml b/src/main/resources/jenkins/kubernetes_helm_install_pipeline.xml index d2be9a5..d63e97c 100644 --- a/src/main/resources/jenkins/kubernetes_helm_install_pipeline.xml +++ b/src/main/resources/jenkins/kubernetes_helm_install_pipeline.xml @@ -59,30 +59,34 @@ pipeline { environment { PATH = "${env.HOME}/bin:${env.PATH}" + HELM_INSTALLED = false + KUBECTL_INSTALLED = false } stages { - stage('Install kubectl and Helm') { + stage('Check and Install kubectl and Helm') { steps { script { - // Install kubectl - sh ''' - if ! command -v kubectl &> /dev/null; then + // Check and install kubectl + if (sh(script: "command -v kubectl", returnStatus: true) != 0) { + sh ''' curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl mkdir -p $HOME/bin mv kubectl $HOME/bin/ - fi - kubectl version --client - ''' + ''' + env.KUBECTL_INSTALLED = true + } + sh "kubectl version --client" - // Install Helm (if not already installed) - sh ''' - if ! command -v helm &> /dev/null; then + // Check and install Helm + if (sh(script: "command -v helm", returnStatus: true) != 0) { + sh ''' curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash - fi - helm version - ''' + ''' + env.HELM_INSTALLED = true + } + sh "helm version" } } } @@ -193,6 +197,17 @@ pipeline { always { sh "rm -f ${WORKSPACE}/kubeconfig" echo "Removed kubeconfig file" + + script { + if (env.KUBECTL_INSTALLED == 'true') { + sh "rm -f $HOME/bin/kubectl" + echo "Removed kubectl" + } + if (env.HELM_INSTALLED == 'true') { + sh "rm -f /usr/local/bin/helm" + echo "Removed Helm" + } + } } success { echo "Helm charts installation and verification completed successfully!" diff --git a/src/main/resources/jenkins/vm_application_install_pipeline.xml b/src/main/resources/jenkins/vm_application_install_pipeline.xml index f3d92f2..5df6831 100644 --- a/src/main/resources/jenkins/vm_application_install_pipeline.xml +++ b/src/main/resources/jenkins/vm_application_install_pipeline.xml @@ -265,6 +265,21 @@ echo ========================================================================== } } } + + post { + always { + echo '>>>>>POST: Cleaning up PEM file' + script { + if (env.PEM_FILE_PATH) { + echo "Deleting PEM file: ${env.PEM_FILE_PATH}" + sh "rm -f ${env.PEM_FILE_PATH}" + echo "PEM file deleted successfully" + } else { + echo "No PEM file to delete" + } + } + } + } } diff --git a/src/main/resources/jenkins/vm_application_uninstall_pipeline.xml b/src/main/resources/jenkins/vm_application_uninstall_pipeline.xml index a2f28df..f35519f 100644 --- a/src/main/resources/jenkins/vm_application_uninstall_pipeline.xml +++ b/src/main/resources/jenkins/vm_application_uninstall_pipeline.xml @@ -180,6 +180,21 @@ echo ========================================================================== } } } + + post { + always { + echo '>>>>>POST: Cleaning up PEM file' + script { + if (env.PEM_FILE_PATH) { + echo "Deleting PEM file: ${env.PEM_FILE_PATH}" + sh "rm -f ${env.PEM_FILE_PATH}" + echo "PEM file deleted successfully" + } else { + echo "No PEM file to delete" + } + } + } + } } ]]>