<p>Put it inside the sh?</p>
<pre><code>withKubeConfig(...) {
  sh “””
    export ...
    kubectl ...
  “””
}
</code></pre>

CC BY-SA 4.0
2021-02-24T18:34:04.470Z
That will not work as by default plugin is working with user access with token not the `key.json`
JackTheKnife
CC BY-SA 4.0
2021-02-24T19:05:26.507Z
So when you run from command line with the `export`, subsequent `kubectl` (per plugin page) reads the contents of the file?
Chris F
CC BY-SA 4.0
2021-02-24T19:11:19.387Z
From the plugin page, you want to somehow use the contents of your `key.json` file for `credentialsId`?
Chris F
CC BY-SA 4.0
2021-02-24T01:03:41.397Z
2021-02-24T01:03:41.397Z
Chris F
<p>Whatever machine you're running <code>kubectl</code> on is reading a kube config (likely <code>~/.kube/config</code>) with a <code>client-certificate-data</code> or <code>client-key-data</code> that doesn't correspond to the server you're communicating with.</p>
<p>You likely want to remove <code>~/.kube/config</code> and use the one you download from Google.</p>

CC BY-SA 4.0
2023-01-17T23:08:19.613Z
2023-01-17T23:08:19.613Z
Evan Carroll
<p>I'm trying to use Jenkins Kubernetes CLI plugin from <a href="https://plugins.jenkins.io/kubernetes-cli/" rel="nofollow noreferrer">https://plugins.jenkins.io/kubernetes-cli/</a> to let deploy artifacts from Jenkins to GKE cluster.</p>
<h2>Expected Behavior</h2>
<p>Get cluster info on <code>kubectl cluster-info</code></p>
<h2>Actual Behavior</h2>
<p>Error out as <code>Unable to connect to the server: x509: certificate signed by unknown authority</code></p>
<h2>Steps to Reproduce the Problem</h2>
<p>Output of generated <code>./kube/config</code></p>
<pre><code>+ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://xxx.xxx.xxx.yyy
  name: my-cluster
contexts:
- context:
    cluster: my-cluster
    user: jenkins-pipeline
  name: my-cluster-jenkins
current-context: my-cluster-jenkins
kind: Config
preferences: {}
users:
- name: jenkins-pipeline
  user:
    username: jenkins-pipelin
</code></pre>
<p>When I run from a command line I need to do</p>
<p><code>export GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json</code></p>
<p>Where that part goes in that plugin?</p>

<jenkins><kubernetes><jenkins-plugins><google-kubernetes-engine>
Jenkins and Kubernetes CLI plugin and GKE
JackTheKnife
# Jenkins and Kubernetes CLI plugin and GKE

(Asked by: username_0 on 2021-02-23)

I'm trying to use Jenkins Kubernetes CLI plugin from https://plugins.jenkins.io/kubernetes-cli/ to let deploy artifacts from Jenkins to GKE cluster.
Expected Behavior
Get cluster info on kubectl cluster-info
Actual Behavior
Error out as Unable to connect to the server: x509: certificate signed by unknown authority
Steps to Reproduce the Problem
Output of generated ./kube/config
+ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://xxx.xxx.xxx.yyy
  name: my-cluster
contexts:
- context:
    cluster: my-cluster
    user: jenkins-pipeline
  name: my-cluster-jenkins
current-context: my-cluster-jenkins
kind: Config
preferences: {}
users:
- name: jenkins-pipeline
  user:
    username: jenkins-pipelin

When I run from a command line I need to do
export GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json
Where that part goes in that plugin?

**Tags:** jenkins, kubernetes, jenkins-plugins, google-kubernetes-engine


---

## 2 answers

### Answer by username_1 on 2021-02-24. Score: 1

Put it inside the sh?
withKubeConfig(...) {
  sh “””
    export ...
    kubectl ...
  “””
}

> **Comments:**
> **username_0**: That will not work as by default plugin is working with user access with token not the `key.json`  
> **username_1**: So when you run from command line with the `export`, subsequent `kubectl` (per plugin page) reads the contents of the file?  
> **username_1**: From the plugin page, you want to somehow use the contents of your `key.json` file for `credentialsId`?  

---

### Answer by username_2 on 2023-01-17. Score: 0

Whatever machine you're running `kubectl` on is reading a kube config (likely `~/.kube/config`) with a `client-certificate-data` or `client-key-data` that doesn't correspond to the server you're communicating with.

You likely want to remove `~/.kube/config` and use the one you download from Google.


---

