在詹金斯管道中得到"error: Missing or incomplete configuration info. Please point to an existing, complete con



我正在尝试使用Jenkins实现CICD,当触发管道时,我得到了以下错误。请对此提出建议。我对这个话题还不熟悉。如果需要更多信息,请告诉我。

我有以下Groovy脚本要实现:

node{
stage('Git Hub Checkout')
{
git credentialsId: 'GitHubCredentials', url: 'https://github.com/account/app'
}
stage('Build Docker Image')
{
bat 'docker build -t imagename/demo:v2 .'
}
stage('Push Docker Image Into Docker Hub')
{
withCredentials([string(credentialsId: 'Docker_Password', variable: 'Docker_Password')]) 
{
bat "docker login -u imagename -p ${Docker_Password}"
}
bat 'docker push imagename/demo:v2'
}
**stage ('Deployment Into Azure')
{
bat 'kubectl apply -f deployment-service.yaml'
}**
}

在构建"阶段(部署到Azure("时,我收到以下错误。请帮忙。

C: \Program Files(x86(\Jenkins\workspace\sampleapplication>kubectl apply-f deployment-service.yaml错误:配置信息丢失或不完整。请指向现有的完整配置文件:

  1. 通过命令行标志--kubeconfig
  2. 通过KUBECONFIG环境变量
  3. 在您的主目录中为~/.kube/config

要直接查看或设置配置,请使用"config"命令。错误:脚本返回退出代码1

注:1.C:\Users\username.kube-->这是kubernetes配置文件所在的位置。

请参考以下参考资料:1:

C:Windowssystem32>kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:07:57Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

2:我已经为windows启用了已安装的docker。我已经在docker for windows插件上启用了Kubernetes。请参阅所附图片。

使用kubernetes插件的windows docker

jenkins构建日志截图

kubernetes配置文件

kubectl--kubeconfig="路径">

kubectl获取吊舱

根据@harrough Manvar的建议,我解决了上述问题。

现在,您可以在管道代码中做一件事,只需在每个kubectl命令后添加:--kubeconfig="path of file"。确保您的kubeconfig文件在jenkin服务器上可用。最佳做法是将配置文件存储在凭据中。

例如:>>kubectl --kubeconfig="C:Usersusername.kubeconfig" cluster-info

cluster-info --> Here you can apply your Kubernetes command.
In my case :  bat """kubectl --kubeconfig=C:\Users\username\.kube\config apply -f deployment-service.yaml"""

注意:在Groovy脚本转义符号问题中,我添加了"""

相关内容

最新更新