Usually when we setup a Jenkins server, we usually use the master to build jobs. The master node is in charge of scheduling jobs, assigning slave nodes, and sending builds to slave nodes for execution. It will also keep track of the slave node state (offline or online), retrieve build results from slave nodes, and display them on the terminal output. This setup work but not recommended due to some security problem, the job ran on master can touch some sensitive on master node.
So in this post i will guide you to create a Jenkins worker node, this node is for building docker image. I assume that we already have a master node up and running. For me i already deployed it to.
As you can see that we only have master node, there is no agent beside this. To create new agent i will use docker compose. We will install
docker-compose. The worker node's architecture is same as.
Create a worker node on Console
I will name it
Permanent Agent. Then click
Create button. After that we need to edit some parameter, for me i will set
Number of executors = 10
The agent will connect to master (controller) by websocket.
Then save and you will saw the manual show how to connect the agent to controller. Ignore it, we just need to grab the secret and host name.
Setup Agent using Docker Compose
The docker file is same as above. Remember to update your secret , host name and
JENKINS_AGENT_NAME , make sure it match with the worker name.
compose file, we defined two services, the first one is
docker:dind. Our agent will use this docker server to build image, start container with predefined image and so on.
Start docker by running
docker compose up -d docker
Check docker log using
docker compose logs -f docker to make sure it's running.
Next time we need to start agent by running
docker compose up -d agent and also need to check the log of this service. The agent need to include
docker cli it seft, we can do that define build block and using custom
Dockerfile for agent.
Dockerfile content is
Start the service.
Check the log.
Verify the worker node
Go back to the web console, open
Manage nodes and clouds you will see the worker node is active.
Test the worker node
I will create a
Multibranch Pipeline job, in the
Jenkinsfile i will update the lable to
copper so it can run on the new worker node that we created.
The content of
Jenkinsfile is like this
After pushing to code, it will triggered the Jenkins to scan respository then run the pipeline, and in the
Console Output we can see that the job ran on
copper worker node.
Let take a look to
Build job, we can see that the docker build process is sucessfully.
That's all, thank for reading.