Search code examples
dockerjenkinskubernetesdigital-oceanjenkins-docker

Docker and Jenkins integration


I've added the BitBucket server integration plugin (https://plugins.jenkins.io/atlassian-bitbucket-server-integration/) and can connect to the BitBucket cloud repo from Jenkins:

enter image description here

But I receive an error when I try to build:

/var/jenkins_home/workspace/bb_add-jenkins-file@tmp/durable-c49dbeca/script.sh: 1: /var/jenkins_home/workspace/bb_add-jenkins-file@tmp/durable-c49dbeca/script.sh: docker: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
ERROR: script returned exit code 127
Finished: FAILURE

So it seems I need to install Docker on the Jenkins instance ?

https://plugins.jenkins.io/docker-build-publish/

I'm following this tutorial to configure Docker with Jenkins: https://medium.com/@karthi.net/docker-tutorial-build-docker-images-using-jenkins-d2880e65b74

and have reached this step:

enter image description here

On my own Jenkins Docker setup page I have :

enter image description here

I'm unsure what Docker URL should be used? Do I need to provision a new container instance within the Kubernetes cluster and run docker within this new instance? This new Docker instance is then the Docker Host URI field?


Solution

  • I think that plugin requires the docker cli to be present. If you run jenkins as a docker image itself, use an image that provides the docker cli, for example https://hub.docker.com/r/trion/jenkins-docker-client

    If you want to use the host docker daemon for building, you need to bind-mount the docker socket. If you want to use a sidecar container to provide the docker daemon, for example using a docker-in-docker setup you can usually use the container name as docker host or kubernetes service name. This depends on how you provide the sidecar container and there is no general answer to that.