Jenkins and Kubernetes Integration using with Helm Jenkins and Kubernetes Integration using with Helm kubernetes kubernetes

Jenkins and Kubernetes Integration using with Helm


you will need to create the Jenkins secrets to add both kubeconfig files for your k8s Clusters, and in the if statement you load the kubeconfig for your environment

for example using your code above

stage('deploy') {  steps {    script {      if (env.GIT_BRANCH == "origin/master") {        def namepsace="dev"        withCredentials([file(credentialsId: 'kubeconfig-dev', variable: 'config')]) {          sh """          export KUBECONFIG=\${config}          helm upgrade --install -f values.dev.yaml --namespace ${namespace}"          """        }      } else if (env.GIT_BRANCH =="origin/test"){        def namepsace="stage"        withCredentials([file(credentialsId: 'kubeconfig-stage', variable: 'config')]) {          sh """          export KUBECONFIG=\${config}          helm upgrade --install -f values.dev.yaml --namespace ${namespace}"          """        }      } else {        def namepsace="prod"        withCredentials([file(credentialsId: 'kubeconfig-prod', variable: 'config')]) {          sh """          export KUBECONFIG=\${config}          helm upgrade --install -f values.dev.yaml --namespace ${namespace}"          """        }      }    }  }}