JENKINS ON DOCKER
Nikhil G R
Senior Data Engineer (Apache Spark Developer) @ SAP Labs India, Ex TCS, 3x Microsoft Azure Cloud Certified, Python, Pyspark, Azure Databricks, SAP BDC, Datasphere, ADLs, Azure Data factory, MySQL, Delta Lake
In this article we will see how to make our own Jenkins Docker image so that on one click, Jenkins will be loaded. We will also see how to automatically open language suitable interpeter.
First create the Dockerfile.
To create the Dockerfile make a new directory using the mkdir command.
Using gedit Dockerfile command open the editor and type the code given below.
After this save the file and type the command:
docker build -t jenkinos:v1
This will build a image after completion.
docker run -it --name c4 --privileged -p 1235:8080 -v /:/host jenkinos:v1
After launching the container successfully we can see something like this.
After this open the browser and type the IP address with specified port number. Here I have used 1236.
After this follow the normal steps to setup the Jenkins.
Now I have used slave master system to run the program.
Go to manage node and click on new node and do following configuration.
Host IP will be our slave system IP and remember the label because all the jobs will run on that label.
In the above image, HOST IP has to be changed and credential has to be added accordingly.
After this click on Save. After some time we can see something like this.
After the slave is setup and it is online go to Jenkins home and create job1.
job1 will pull the data from git repository and copy it to the folder which is mounted on the docker and it will also check extension of the file and according to that, it will launch the docker image.
Here, I have used port 9993.
job2 will check whether the site is working or not.
job2 will trigger the job3 irrespective of the build.
In job3, if the container is working good then it will do nothing but if the container is not running as required it will send an Email to the developer and again it will trigger job1 to launch the container.
The mail.py code can be found on my github repository as attached below.
Conclusion
We have setup a jenkins with the help of docker image and setup a master slave system to run the docker image according to language interpreter. If the container fails to start, the mail is sent to the developer and and it will try to relaunch it again by itself.