I have a jenkins installed on my linux machine and connected it to my kubernetes cluster.
I’ve installed docker
and docker-pipeline
plugin inside jenkins and they can be found under /var/lib/jenkins/plugins
:
docker-build-step
docker-build-step.jpi
docker-commons
docker-commons.jpi
docker-java-api
docker-java-api.jpi
docker-plugin
docker-plugin.jpi
docker-workflow
docker-workflow.jpi
and configured in Global Tool Configuration
:
However when I run docker.build
or even sh 'docker ps'
inside my pipeline it throws:
/home/jenkins/agent/workspace/nodejs@tmp/durable-492ddc4c/script.sh: 1: docker: not found
EDIT
:
I’ve built my own image with docker and when I exec into it I can run docker
command but pipeline still throws docker not found
command and found out it is because jnlp
doesn’t have docker installed. Any ideas how to fix it inside jenkins-inbound-agent
?
2
Answers
I've fixed it by adding:
in
environment
part of my pipeline. And it had appeared in my $PATH while checking inside the pod.Then I've had issues while invoking
docker.withRegistry()
and solved it by usingdocker.withTool()
as following:It might not be the prettiest solution but it worked for my homelab use-case.
You should customize the jenkins/inbound-agent to add
docker command
, a minimal example as next:Dockerfile:
Build:
Above will install a docker client binary in customized image to let you have docker command in
inbound-agent
. But still, you need mountdocker unix socket
toinbound-agent
when start it, also you need to use your customizedagent image
, like next:Start agent:
Then, we could verify it’s ok in agent with next: