I am trying to implement CICD using Jenkins, While trigger pipeline, i am getting below error. Please advice on this. I am new to this subject. Let me know if more information needed.
I have following Groovy script to achieve:
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'
}**
}
While building "stage ('Deployment Into Azure')" i am getting following error. Please help.
C:\Program Files (x86)\Jenkins\workspace\sampleapplication>kubectl apply -f deployment-service.yaml error: Missing or incomplete configuration info. Please point to an existing, complete config file:
To view or setup config directly use the 'config' command. ERROR: script returned exit code 1
Note: 1. C:\Users\username.kube --> This is the location where kubernetes config file located.
Please refer following reference: 1:
C:\Windows\system32>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: I have enabled installed docker for windows. I have enabled Kubernetes on that docker for windows plugin. Refer attached images.
As per @harsh Manvar advise, I resolved the above issue.
You can do one thing now in your pipeline code just add : --kubeconfig="path of file"
after each kubectl command. make sure your kubeconfig file available at jenkin server. best practices is to store the config file in credentials.
For ex:>> kubectl --kubeconfig="C:\Users\username\.kube\config" 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"""
Note: In Groovy script escape symbol issue purpose i have added """