Integrating the Git, Jenkins, Docker for automation
In this task, I have integrated the Docker with Jenkins and Git for continuous integration.
- Create the docker image which contains the Jenkins and Git.
- Run the Jenkins image and pull the git repo from the GitHub as soon and the developer commits the file.
- By looking at the file whether HTML, PHP, etc Jenkins will run the respective language interpreter in the docker images.
- If for some reason the interpreter stops working or any error occurred the Jenkins will send the email to the developer to notify then.
- Once if for any reason the interpreter stops the job 4 will start the interpreter again of the respective language.
Creating the Docker File :
- For creating the docker file save the file name with Dockerfile.
RUN yum install wget -y
RUN wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
RUN yum install sudo -y
RUN yum install git -y
RUN yum install java-11-openjdk.x86_64 -y
RUN yum install jenkins -y
RUN yum install python3 -y
RUN yum install curl -y
RUN echo -e "jenkins ALL=(ALL) NOPASSWD: ALL" >> etc/sudoers
COPY failed.py /CMD java -jar /usr/lib/jenkins/jenkins.war
Here’s the various keywords we used in it:
- FROM: the base image to be used for the container.
- RUN: execute these commands on the base image obtained.
- CMD: to start a service when the container starts.
- COPY: to copy the content inside the image.
Building the Dockerfile :
docker build -t jenkins:latest .
- On successful build, you will see a screen like this.
Running the Jenkins Image :
docker run -it --privileged -p 9000:8080 -v /:/host jenkin:latest
- Privileged: It is used for special access to be used later while playing with dockers.
- -V : to mount the local files inside the containers.
- Copy the marked password.
- In administrator password paste the above copied password .
Now we will be moving on to our jobs:
- This will be triggered as soon as Job1 completes and will deploy a container on the host system.
- Job3 will be successfully built if the test fails so it can go to Job4 and mail to developer.
- failed.py conatins
- This is set for monitoring job to check every minute for the status of the container.
- Thanks, hope you guys will like my article. if you have any suggestion or query will free to ask.
#Happylearning #keepsharing #devops #integration