Task Description 👉
- Create container image that’s has Jenkins installed using dockerfile
2. When we launch this image, it should automatically starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push repo to Github.
5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
6. Job3 : Test your app if it is working or not.
7. Job4 : if app is not working , then send email to developer with error messages.
8. Create One extra job job5 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again.
Let see the procedure :
make a blank repo on github and push a html page on it using git bash (offline)
either manually push or create hooks to automatically push the code using git hooks
[inside it just write :
mv post-commit.txt post-commit
firstly do check these :
- systemctl start docker
- systemctl status docker → (must be Active)
- setenforce 0
- systemctl start httpd
firstly make a directory on /
Docker setup for handling request over Tcp protocol :
firstly we connect client network to the outside world known as socket networking.
add this line :
-H tcp:// <your rhel8 ip>:<any port no.>
# but ususally we give port no. -> 4243
# important commands compulsory to perform :
systemctl restart docker
as we have changed the services so must reload daemon to apply changes and restart the docker . we have done this so that our outside system (in our case jenkins )can connect to base system docker and recognise its commands . and Run this also,
— > export DOCKER_HOST=192.168.43.72:4243
Build the Jenkins image :
here, in my case i have used image name (ownimage) and version (v1)
docker build -t <image name>:<version>
Launching docker container (Run the Docker image) :
docker run -dit -p 8085:8080 --name os ownimage:v1
here, 8085 is my port no. where i exposed my jenkins and os is the container name , as you run this it give a id that is containers running id
To access the jenkins login page we have used redhat ip:port no.(exposed)
For password go inside the container by the ‘exec ‘ & Run command:
docker exec os cat /var/lib/jenkins/.jenkins/secrets/initialAdminPassword
Alternative for Establishing socket networking:
directly run command ->
make a blank directory inside the container, i named it task2:(in my case i applied sudo before every command because i don’t provide root access permission )
docker exec os sudo mkdir /root/task2/
pull github repo and copy the file on task2 directory.
Job 2 :
launching two containers inside jenkins Docker container OS ,one for html that is htmlenv and other for python files that is pythonenv
Job 3 :
testing job checking website is working or not.
Job 4 :
this job is mailing job which email the developer if any error occurred in deployment of page (i.e., job 3)
Firstly perform following steps :
- got to gmail > mange your account > security
turn off the two step verification and turn on Less secure app acess
2. go to jenkins > manage jenkins > Manage plugins
install 3 plugins :
- Email Extension
- Email Extension template
- job direct mail
3. go to jenkins > manage jenkins > configure system >Email notification and fill following information.
test the configuration ,
Job 5 :
This job will check app is working fine or not and if not then stop the container ,remove it and relaunch
As here ,all the steps are finished and model is set .
* Build pipeline *
At last , my pipeline has successfully built :
Thank you ! 😃