i have a Deploy stage in jenkins like below.
stage('Deploy service to K8S') {
steps {
withDockerContainer(image: "gcr.io/google.com/cloudsdktool/cloud-sdk", toolName: 'latest'){
withCredentials([file(credentialsId: 'jenkins_secret', variable: 'GC_KEY')]) {
sh("HOME=$WORKSPACE gcloud --quiet auth activate-service-account --key-file=${GC_KEY}")
sh("HOME=$WORKSPACE gcloud container clusters get-credentials test --zone us-central1-c --project ${PROJECT_ID}")
sh("kubectl get pods")
}
}
}
}
Despite of Jenkins logs show me that autentication was succedd. But kubectl get pods commands fail with this error : The connection to the server localhost:8080 was refused - did you specify the right host or port?
What can be the issue there ?
P.S I can run it inside docker manually.
kubectl
is looking in the wrong location for yourkubeconfig
. You could most easily solve this with anenv
map, but there are multiple ways in general to solve this. – Matt Schuchard