Lab 25:Jenkins setup
- Get link
- X
- Other Apps
Jenkins setup
Continuous
integration is the most important part of develops that is used to integrate
various devops stages.Jenkins is the most famous and continuous integration
tool.
Jenkins s an open automation tool written in
java with plugins built for continuous integration purpose. Jenkins is used to
build and test your software projects
continuously making it easier for developers to integrate to the project changes
to the project and making it , and making it easier for users to obtain a fresh
build . It also allows you to continuously deliver you software by integrating
with a large number of testing and deployment technologies
Pre-Requirements:
Create
an instance
Install
java,Jenkins ,docker ,git ,in an instance
Sign
in git hub,create a repository
Create
a httpd image in your local repo
First
create a repo in central repository
If
you don’t have an account refer the below link and create an account
From
the above link create an account
After
creating an account In the git hub create a respository
àrepo
is nothing but software storing locations
You
will get a page like this
Give
a name for the project
And
a description
And
then click on create
You
will get page like this
Now
create local repo
Create
a simple docker file push to get hub
Open
git bash
Now
copy the created repo url
Use
the command git clone<url>
- Git clone command
copies an existing git repository in a directory at another location.
You
have created a repo in your local system
Now
create a simple httpd file
Go
inside the created repository
Cd
Jenkins_ci
In
that create a httpd fileàvi docker file -àwrite
the below lines in vi docker file
FROM
httpd
COPY
index.html/usr/local/apache2/htdocs/
To
insert the vi editor press esc and enter i and enter above lines
After
entering save and exit
Esc
shift+: and write wq! To save the content and exit
We
just created a file its untracked file
To
track the file and add the file
Use
the command git add<filename>
To
see the status of a file enter the command git status
Now
file is tracked but still is temporary we want to do permanent we need to
commit the file
#git
commit-m <message>
Now
create an index file
#vi index .html
And
write any one like Jenkins
Save
and come out of the editor
Now
index.html is untracked file.
To
track the file add the file
Git
add <filename>
Now
the file is tracked but its in temporary and to do permanent commit the file
#git
commit –m<message>
Check
the status
git
status
Now push this files get hub
Before
that set the environmental variables
git-config—global
user .email mailid --------give the email
gitconfig --global user.name username-------give the user name
Note
:Give the same mail id which you have used for the account in git hub and same user name for git hub.
No
login to remote repository which means git hub
Use
the below command
#git
remote add orign git@github.com:<username>/jenkins ci.git
If
you already login it will stay remote orign already exists.
Next
push the files to remote repo
Now
check the github whether the files came or not
Files
are there
We
will use this repo url while creating a job in Jenkins
Step2:create
an instance
Refer
above how to create an ec2 instance
Select
redhat ami.
Give
security groups ssh and all tcp
Login
to the server ssh and use public ip address of an instance
Without
java Jenkins won’t work so before installing Jenkins install java.
#yum install java-1.8.0-openjdk-devel
To
check the version of java use command java-version
Now
install the Jenkins
Before
that enable the epel
# curl
--silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo| sudo
tee /etc/yum.respos.d/Jenkins.repo
Now
install the Jenkins
#yum install jenkins—nogpgcheck—y
Start
and enable the Jenkins
Systemctl
start Jenkins
Systemctl
enable Jenkins
Enable
the Jenkins to os level
Now
check whether the Jenkins running or not.
#ps-ef | grep-i jenkins
You
get a single line status means Jenkins is not working
Now
install docker and git as well
#yum
install docker and start the service
#systemctl
start docker
Before
that enable the epel
Then
install docker and start service
Now
start the service
systemctl
start docker
systemctl
enable docker
Now
check the docker is running or not
#ps-ef|grep -i docker
Now
install git
#yum
install git
Now
lets connect to the Jenkins
Open
in the browser by using public <ipaddress>:8080
Because
Jenkins will run on 8080 port number
Now
copy url and paste in the server to get password to login to Jenkins .
#cat/var/lib/Jenkins/secrets/initialAdminpassword
Copy
that password and paste in Jenkins url
Click
on continue
You will get a page like this
Select install suggested plugins.
You will get a page like this
Just provide all the details
After
providing details just click on save and continue
You
will get a page like this
Click
on save and finish
Click
on start using Jenkins
You
will get a page like this
Create a job
click on create new job or else click on create new item
Item
is nothing but a job
Enter
an item name
Select
the job style
Select
free style project
Then
click on ok
You
will get a page like this
Give
a description
And
then click on source code management select git
Here
give the repo url which we created in the git hub
Give
this url
Now
come to build section
Drop
down build setup
Select
execute shell
From
here we build the image
You
will get a page like this here we can run commands
echo "i am bulding docker image"
Sudo
docker build -t httpd-web:1.
Echo "list the docker images"
Sudo
docker images
echo "login to the docker hub"
Sudo
docker login -u xxxx -p xxxxxx
Echo "tag the local image"
Sudo
docker tag httpd -web:1<username>/httpd-web:$image tag
Echo "push the image into docker hub"
Sudo
docker push<username>/httpd-web:1
Click
on apply and save
Click
build now to build the image
Build
has failed
Click
on 1 to see the console out put to see why the build has failed
Click
on console output
While
install Jenkins it will create an use called Jenkins user as jenkin is normal
user he cant built the image
Make
Jenkins as sudoer user go to the bit bash
Enter
visudo
vieditor
will open make jenkin as sudoer where he can have all the right to do
Go
to the 93 line enter jenkin ALL=(ALL) Nopasswd :all
Save
and Quit
Now
come to the Jenkins UI and build the image again
Build
failed
Go
to console output see the error
Image
is built but cannot push to the docker hub
As
we took redhat ami we cannot to the docker hub
We
need to edit the /etc/container/registries.d file
Go
to the bit bash vi/etc/containers /registries.conf
Set
the line numbers edit the line number 12
just keep docker .io in double quotes remaining delete
Save
and quit
And
restart the service
#systemctl
restart docker
Come
to the Jenkins page and again build the image
Now image got build
Now
go to docker hub and check whether the image pushed or not
Execrise :1)Install the Jenkins in redhat and ubuntu ami.
2)Make
Jenkins user’s as a sudoer user.
- Get link
- X
- Other Apps






























































Comments
Post a Comment