Jenkins multiple pipelines

Jenkins architecture is fundamentally “Master + Agent”, the master is designed to do the co-ordination and provide the GUI and API endpoint, and the Agents are designed to execute the work.

Jenkins can run on distributed mode, this may be for scale or to provide different tools and we can launch jenkins en multiple pipelines simultaneously, it can work on parallel

Here I will show an example how to install multiple agents to a Jenkins master. In my example, I use docker to install Jenkins master and vagrant to install two machines as agents.

Create agent machines by vagrant

I created 2 machines by vagrant with the Vagrantfile as below, you can go the directory of this file and run the command :

1
2
vagrant up

[Vagrantfile]

Run master via docker

1
2
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

copy the password to the interface of jenkins, configure user information, install the plugins recommended and then we can access to jenkins home page

Add agent

go to Manage Jenkins/Manage Nodes and click “New Node” button, we give a Node name and check Permanent Agent

SSH connexion

In the first example, we will add an agent via SSH:
Before doing that, I generated the ssh key inside of docker container, and copy id_rsa.pub to ~/.ssh/known_hosts in agent

1
2
ssh-keygen -t rsa -b 4096 -C "sdmj45@gmail.com"

Labels: group name of the agent
Host: agent ip
Credentials: configure credential as below, we give the username as vagrant and private key generated in docker container

Launch agent:
We can click Launch agent button to launch Agent

Java Web Start connexion

In the second example, we will add an agent via Java Web Start:

Labels: group name of the agent

Launch agent:
We can launch agent by “Run from agent command line”: copy the agent.jar to agent machine and run the command by changing localhost:8080 to host_ip:8080

Multiple pipeline build

I add a new build of test and execute a simple command, I added “sleep 30” in order to keep some time in the building

1
2
3
echo "hello slave"
sleep 30
echo "bye slave"

and then I can launch multiple pipeline build as follow (as there are 2 executors in each agent, I can launch 4 build simultaneously)