Dynamic provisioning means provision of slave nodes as and when needed i.e. when we need to run any job in jenkins to save the resources
Now let's try to implement this concept by integrating JENKINS with MAVEN using MASTER and SLAVE in Linux OS.
Jenkins master connects to the docker host using REST APIs. So we need to enable the remote API for our docker host.
Open the docker service file /lib/systemd/system/docker.service. Search for ExecStart and replace that line with the following.
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
Reload and restart docker service.
$ sudo systemctl daemon-reload
$ sudo service docker restart
Validate API by executing the following curl commands. Replace 54.221.134.7 with your host IP.
$ curl http://localhost:4243/version
$ curl http://54.221.134.7:4243/version
-
Head over to Jenkins Dashboard –> Manage Jenkins –> Manage Plugins.
-
Head over cloud configuration under Manage Jenkins –> Manage Nodes and Clouds
- Add docker Agent Template.
Replace “Docker URI” with your docker host IP. For example, tcp://10.128.0.3:4243 You can use the “Test connection” to test if Jenkins is able to connect to the Docker host.
First we need plugins i.e. dependencies i.e. Git, Docker and Maven from Manage Jenkins --> Manage Plugins.
- Create New Freestyle Project:
- Now go to GENERAL and set options.
By-default job runs in master so we need to restrict it to run inside the slave-nodes.
- Now go to SOURCE CODE MANAGEMENT and set options.
Here we take code from GitHub for testing purpose.
- Now go to BUILD and set options.
We need to perform operations i.e. Test --> Compile --> Package.
- Now go to POST BUILD ACTIONS and set options.
As we want to archive the package i.e. called ARTIFACT to download it in .jar extension to use it directly.
- Now build the job in jenkins.
Now as soon as we build the job then docker will launch the container in which specified slave will set and then run the job inside it.
And after running the job automatically the container in docker and slave in cluster will be deleted
- Console Output will show the output and whole process/steps involved in it.
-Workspace will show all the files and folders and we can also downloade The Artifact