Introduction to Continuous integration:
Jenkins is a Continuous Integration (CI) server or tool which is written in java platform. Continuous Integration is a practice of running our tests on a non-developer machine automatically every time we push new code into the source git repository. JENKINS is an open-source free download and install tool.
You can visit here to learn CI/CD with Devops tools in detail.
Let’s take a deep dive and learn more about the fundamentals of Continuous Integration.
Build: Build jobs are at the heart of the Jenkins build process. Simply put, you can think of a Jenkins build job as a particular task or step in your build process. This may involve simply compiling your source code and running your unit tests.
- Test: Testing in DevOps is automated within the build pipeline to ensure that the applications are deployable.
- “continuous integration” and application delivery.
- Git: Git is a Distributed Version Control tool that is used to store different versions of a file in a remote or local repository. It is used to track changes in the source code.
- Continuous integration
- Open-source software
- Installation is easier in all operating systems
- Ant, maven, docker, and many others can be used in it
- Builds can be made based on user requirements
- Git, maven, bitbucket can be easily linkup with it
- It has more than 1000+ plugins to make work easier
- Easy to integrate with Aws Ec2 with plugin.
Install Jenkins on AWS EC2 Cloud
Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and other Unix-like operating systems. As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project.
Prerequisites to Install Jenkins:
- EC2 RHEL
- With Internet Access
- Security Group with Port 8080 open for Internet
- If we are using AWS Ec2 for Jenkins, setup port 8080 should be open in security groups in INBOUND Rules.
- Java v1.8.x
- Should have at least basic knowledge on Linux commands, Git commands.
- Go to Ec2 Dashboard and click on Network security and choose currently Running Ec2 security group.
You can visit here to understand more information about CI/CD pipeline with AWS Cloud
Steps to Launch Ec2 instance:
- Login to AWS console. Select Ec2 launch Instance.
- Select Type of Operating system Amazon Ec2 instance. Choose “Amazon Linux AMI”.
- Select Amazon Ec2 instance as per your project needs.
- Check details VPC, Ec2 Region and leave another options default. Click Next.
- Select storage options by default. It will give 8GB and we can increase volume space.
- Review detail and create Keypair or we can select Existing key pair for Ec2. click on Launch instance.
Steps to login Ec2 instance:
- Download putty and puttygen from “ https://www.putty.org” and install.
- Open puttygen and convert .pem file to .ppk file and save as a private key file.
- Launch putty and use below usernames to login as per our Ec2 instance Types.
For an Amazon Linux AMI, the user name is ec2-user.
•For a RHEL AMI, the user name is ec2-user or root.
•For an Ubuntu AMI, the user name is ubuntu or root.
•For a Centos AMI, the user name is centos.
•For a Fedora AMI, the user name is ec2-user.
•For SUSE, the user name is ec2-user or root.
- Open putty and set Ec2 instance Public Ip and check port number 22.
- Next, click on the + button next to the SSH field to expand this section. Then click on Auth (which stands for authenticate) and enter the name of your private key file (i.e. the ppk file) where it says Private key file for authentication (if you click on browse you can easily search for the directory where you have stored it).
How to install Java
We can search and install java in Ec2 server by using below command:
# yum search java
# yum install java-1.8*
# yum -y install java-1.8.0-openjdk
Let’s confirm Java Version and set the java home
# java -version
The output should be something like this:
java version “1.8.0_181”
OpenJDK Runtime Environment (amzn-22.214.171.124.80. amzn1-x86_64 u181-b00)
OpenJDK 64-Bit Server VM (build 24.181-b00, mixed mode)
find /usr/lib/jvm/java-1.8* | head -n 3
# To set it permanently update your .bash profile
source ~/.bash profile
STEPS TO INSTALL JENKINS AND CONFIGURE
You can install Jenkins using the rpm or by setting up the repo. We will set up the repo so that we can update it easily in the future. Get the latest version of Jenkins from https://pkg.jenkins.io/redhat-stable/
yum -y install wget
wget -O /etc/yum.repos.d/Jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm –import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install Jenkins
# sudo systemctl start Jenkins
# sudo service Jenkins start
# To check whether it started successfully, run:
systemctl status Jenkins or service Jenkins status
You should see something similar to this:
By default, Jenkins runs at port 8080. You can access Jenkins at
- Password Location:/var/lib/Jenkins/secrets/initial admin password
- Wait for plugins installation to complete.
- Create username and password and click “save and continue”.
- On the next page, you will be asked to set the URL for the Jenkins instance. The URL field will be populated with an automatically generated URL.
- Complete the setup confirm the URL by clicking on the Save and Finish button.
Let’s create Jenkins Job step by step:
To create a Jenkins project, we need to access Jenkins Dashboard with our Server IP address and port 8080 “http://localhost:8080”. Enter user credentials to login.
After login into Jenkins Dashboard, click on “CREATE NEW ITEM” on the right side.
Choose “Free style project”
Click on “OK”.
Add description of the Project.
Now, we need configure Git repository. Visit https://github.com/jenkins/firstproject.git. You will find it under “source code management”.
For this Jenkins and git integration, we need to install git plugin in Jenkins.
Go to manage Jenkins-à manage plugins
Search for Git plugin and install plugin.
After installing Git plugin, we need to add Jenkins URL in Git webhooks.
Go to repository settings and click on webhook and add Jenkins URL.
Click on webhooks and add webhook Jenkins URL and save.
Now we can integrate Git with Jenkins to push changes from Git to Jenkins for our project.
Now we need to provide all the details, since it’s time to build the code. The settings under the build section will help you build the code at the time you want.
- Click on “Add build step”
- Select “execute windows or shell command”
- Now execute project code in shell.
- click on save and apply.
- Build code
Since we are done with Build, we need to check console output.
Jenkins is a “DevOps” open-source project written in Java that runs on Windows, macOS, and other Unix-like operating systems. It’s free, community-supported, and might be your first-choice tool for continuous integration. Primarily deployed on-premises, Jenkins can run on cloud servers as well.
Hope this article will help to learn Jenkins.
Written by Jagadeesh