<p>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.</p>

<p>I have following Groovy script to achieve:</p>

<pre><code>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'
    }**

}
</code></pre>

<p>While building "stage ('Deployment Into Azure')" i am getting following error. Please help.</p>

<p>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:</p>

<ol>
<li>Via the command-line flag --kubeconfig</li>
<li>Via the KUBECONFIG environment variable</li>
<li>In your home directory as ~/.kube/config</li>
</ol>

<p>To view or setup config directly use the 'config' command.
ERROR: script returned exit code 1</p>

<p>Note:
     1. C:\Users\username.kube   --> This is the location where kubernetes config file located.</p>

<p>Please refer following reference:
1:</p>

<pre><code>C:\Windows\system32&gt;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"}
</code></pre>

<p>2:
I have enabled installed docker for windows. I have enabled Kubernetes on that docker for windows plugin.
Refer attached images.</p>

<p><a href="https://i.stack.imgur.com/EpIBN.png" rel="nofollow noreferrer">docker for windows with kubernetes plugin</a></p>

<p><a href="https://i.stack.imgur.com/pOB83.png" rel="nofollow noreferrer">jenkins build log screenshot</a></p>

<p><a href="https://i.stack.imgur.com/q4XbW.png" rel="nofollow noreferrer">kubernetes config file</a></p>

<p><a href="https://i.stack.imgur.com/fWhZ9.png" rel="nofollow noreferrer">kubectl --kubeconfig="path"</a></p>

<p><a href="https://i.stack.imgur.com/3bv4l.png" rel="nofollow noreferrer">kubectl-get-pods</a></p>

V. Periyasamy
<p>As per @harsh Manvar advise, I resolved the above issue.</p>

<p>You can do one thing now in your pipeline code just add : --<code>kubeconfig="path of file"</code> after each kubectl command. make sure your kubeconfig file available at jenkin server. best practices is to store the config file in credentials.</p>

<p><strong>For ex:>></strong> <code>kubectl --kubeconfig="C:\Users\username\.kube\config" cluster-info</code></p>

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

<p>Note: In Groovy script escape symbol issue purpose i have added <code>"""</code></p>
