[JIRA] (JENKINS-50864) kubernetes-cli-plugin is not working.

201 views
Skip to first unread message

sunilchaurha@gmail.com (JIRA)

unread,
Apr 18, 2018, 9:21:02 AM4/18/18
to jenkinsc...@googlegroups.com
Sunil Chauraha created an issue
 
Jenkins / Bug JENKINS-50864
kubernetes-cli-plugin is not working.
Issue Type: Bug Bug
Assignee: Max Laverse
Attachments: error-log.txt
Components: kubernetes-cli-plugin
Created: 2018-04-18 13:20
Labels: pipeline kuberenetes-plugin
Priority: Major Major
Reporter: Sunil Chauraha

I have configured kubernetes-cli plugin on my Jenkins to deploy my docker image on Kubernetes cluster.

But when I run my job, I am getting error as below. Detailed error is attached as error-log.txterror-log.txterror-log.txt.

 
Caused: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:245)
at hudson.Proc$LocalProc.<init>(Proc.java:214)
 

Jenkins Pipeline stage:

node {
label '****'
script {
git (url: 'git@gitlab.****.com:***/kubectl-cli.git', branch: 'master', credentialsId: 'sousr'
}
stage('List pods') {

withKubeConfig(
credentialsId: 'token-g88c9:sklnbp7rktcf4b99vg2vzbh7t66v7rbrp7rk6js6pcv6dmmb5jlr92', 
serverUrl: 'https://maui1.*****.com/v3') {
sh 'kubectl get pods' 
}
}
}

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

sunilchaurha@gmail.com (JIRA)

unread,
Apr 18, 2018, 10:11:01 AM4/18/18
to jenkinsc...@googlegroups.com
Sunil Chauraha commented on Bug JENKINS-50864
 
Re: kubernetes-cli-plugin is not working.

I am using Jenkins version: 2.60.2

max@laverse.net (JIRA)

unread,
Apr 18, 2018, 10:32:02 AM4/18/18
to jenkinsc...@googlegroups.com

Hi Sunil Chauraha
Are you sure kubectl is installed on your nodes ?
And in the PATH used by Jenkins ?

sunilchaurha@gmail.com (JIRA)

unread,
Apr 18, 2018, 1:14:02 PM4/18/18
to jenkinsc...@googlegroups.com
Sunil Chauraha assigned an issue to Sunil Chauraha
Change By: Sunil Chauraha
Assignee: Max Laverse Sunil Chauraha

sunilchaurha@gmail.com (JIRA)

unread,
Apr 18, 2018, 1:15:02 PM4/18/18
to jenkinsc...@googlegroups.com
Sunil Chauraha assigned an issue to Max Laverse
Change By: Sunil Chauraha
Assignee: max ashton Max Laverse

sunilchaurha@gmail.com (JIRA)

unread,
Apr 18, 2018, 1:15:02 PM4/18/18
to jenkinsc...@googlegroups.com
Sunil Chauraha assigned an issue to max ashton
Change By: Sunil Chauraha
Assignee: Sunil Chauraha max ashton

max@laverse.net (JIRA)

unread,
Apr 18, 2018, 2:25:02 PM4/18/18
to jenkinsc...@googlegroups.com
Max Laverse assigned an issue to Sunil Chauraha
Change By: Max Laverse
Assignee: Max Laverse Sunil Chauraha

max@laverse.net (JIRA)

unread,
Apr 18, 2018, 2:25:02 PM4/18/18
to jenkinsc...@googlegroups.com
Max Laverse started work on Bug JENKINS-50864
 
Change By: Max Laverse
Status: Open In Progress

max@laverse.net (JIRA)

unread,
Apr 18, 2018, 2:25:02 PM4/18/18
to jenkinsc...@googlegroups.com
Max Laverse stopped work on Bug JENKINS-50864
 
Change By: Max Laverse
Status: In Progress Open

sunilchaurha@gmail.com (JIRA)

unread,
Apr 19, 2018, 2:26:02 AM4/19/18
to jenkinsc...@googlegroups.com

Yes kubectl is installed and added to PATH.

sunilchaurha@gmail.com (JIRA)

unread,
Apr 19, 2018, 5:17:01 AM4/19/18
to jenkinsc...@googlegroups.com
Sunil Chauraha assigned an issue to Max Laverse
Change By: Sunil Chauraha
Assignee: Sunil Chauraha Max Laverse

max@laverse.net (JIRA)

unread,
Apr 19, 2018, 5:26:02 AM4/19/18
to jenkinsc...@googlegroups.com

Can you please double check ?
I can't see any reason why the plugin would not work for you. There is nothing done manipulating path in the plugins. It's just executing raw commands.
You can find the PATH in the connection logs to your slave.

If it's an SSH slave for example, https://<jenkins-host>/computer/slave5.putnaminv.com/log

In the meantime I'll release a new version that displays a clear message if the binary is not in the path

max@laverse.net (JIRA)

unread,
Apr 19, 2018, 5:28:01 AM4/19/18
to jenkinsc...@googlegroups.com
Max Laverse edited a comment on Bug JENKINS-50864
Can you please double check ?
I can't see any reason why the plugin would not work for you. There is nothing done manipulating path in the plugins. It's just executing raw commands.
You can find the PATH in the connection logs to your slave.

If it's an SSH slave for example, https://<jenkins-host>/computer/slave5.putnaminv.com/log

In the meantime I'll release Can you try creating a new version job that displays just does a clear message if the binary is not kubectl command, without wrapping it up in the path plugin withKubeConfig?

max@laverse.net (JIRA)

unread,
Apr 19, 2018, 5:28:02 AM4/19/18
to jenkinsc...@googlegroups.com
Max Laverse assigned an issue to Sunil Chauraha
Change By: Max Laverse
Assignee: Max Laverse Sunil Chauraha

sunilchaurha@gmail.com (JIRA)

unread,
Apr 19, 2018, 8:53:02 AM4/19/18
to jenkinsc...@googlegroups.com

Thanks Max Laverse.

Now I got what is the issue, Even PATH is set but Jenkins slave is not taking it and its throwing the error.

But if you could create a release with some more logging would be very helpful.

sunilchaurha@gmail.com (JIRA)

unread,
Apr 19, 2018, 9:44:02 AM4/19/18
to jenkinsc...@googlegroups.com
Sunil Chauraha closed an issue as Not A Defect
 

I had an issue on Jenkins master and the PATH was not updated properly there.

Slave nodes ere not able to locate kubectl due to incomplete path for kubernetes cli.

 

Change By: Sunil Chauraha
Status: Open Closed
Resolution: Not A Defect

jglick@cloudbees.com (JIRA)

unread,
Jun 12, 2019, 3:35:02 PM6/12/19
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
Change By: Jesse Glick
Labels: kuberenetes-plugin pipeline
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

edward.thorne@gmail.com (JIRA)

unread,
Jan 8, 2020, 4:34:03 PM1/8/20
to jenkinsc...@googlegroups.com

For others that may be experiencing this issue, here's some information that may be useful.

By default, the Jenkins environment on an RPM installed (Linux) system will look like the following:

SHELL=/bin/bash
USER=jenkins
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
LANG=en_US.UTF-8
HOME=/opt/jenkins
SHLVL=2
LOGNAME=jenkins
_=/etc/alternatives/java

The recommended installation instructions for kubectl on Linux have the binary installed in /usr/local/bin (not in the default path of Jenkins). Even though /usr/local/bin is in the path in bash shells, it's not in the daemon's path with the default settings. Using the PATH+WHATEVER pattern you can get /usr/local/bin in the path for shells, but not the Jenkins process. This allowed me to work around the issue in this way:

withKubeConfig([
        credentialsId: '7a1146c7-1791-4197-a8fd-f6a97abec862'
        // , contextName: contextName
]) {
    // switch context from default to target environment
    sh "kubectl config use-context ${contextName}"
    // deploy the resources (without pushing)
    sh 'kubectl apply -k .'
    // wait for deployment to complete
    sh "kubectl rollout status deployment/${projectName} --timeout=2m"
}

If I tried to set the context name in the parameter, I got the exception observed in this ticket. This likely stems from the launcher not understanding the PATH+WHATEVER modifications that add /usr/local/bin to the path for pipeline shell commands that you can see above.

This feels like a shortcoming of the plugin documentation in that the kubectl binary must be in the path visible to the Jenkins process(es) which can be considerably different from traditional login shell paths or even pipeline shell paths. With the documented installation location as /usr/local/bin, I'm surprised more instances of this haven't occurred.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

max@laverse.net (JIRA)

unread,
Feb 16, 2020, 7:05:02 AM2/16/20
to jenkinsc...@googlegroups.com

Thank for the feedback Ed Thorne.
For your information, the latest version of the plugin doesn't rely on `kubectl` being available on executors anymore and therefore those issues with setting the PATH shouldn't happen anymore.

tamerlaha@gmail.com (JIRA)

unread,
Feb 26, 2020, 11:28:03 PM2/26/20
to jenkinsc...@googlegroups.com
ipleten commented on Bug JENKINS-50864

On 1.8.2 issue has gone. Thank you!

This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages