问题描述
我正在尝试使用Jenkins管道中的头盔部署容器。我已经为jenkins安装了Kubernetes插件,并在凭据中提供了本地运行的kubernetes URL和配置文件。当我做'Test connection'
时,它正在显示'Connected to Kubernetes 1.16+'
。
但是当我从管道运行helm install命令时,它给出了错误
Error: Kubernetes cluster unreachable: the server Could not find the requested resource
注意:通过使用withCredentials
并传递cred文件变量名称(在jenkins凭据中创建),我可以使用CLI以及Jenkins管道执行所有操作。我只想做到这一点而无需将其包装在'withCredentials'
中。
Jenkins和kubernetes分别在Windows 10上运行。请帮助
解决方法
Helm使用kubectl配置文件。我正在使用这样的步骤。
steps {
container('helm') {
withCredentials([file(credentialsId: 'project-credentials',variable: 'PULL_KEYFILE')]) {
sh """
gcloud auth activate-service-account --key-file=${PULL_KEYFILE} --project project-name
gcloud container clusters get-credentials cluster-name --zone us-east1
kubectl create namespace ${NAMESPACE} --dry-run -o yaml | kubectl apply -f -
"""
helm upgrade --install release-name .
}
}
}