Basics of Jenkins

Jenkins:

Jenkins is a free and open-source continuous integration tool and its code is written in Java. it offers a simple way to set up a continuous integration or continuous delivery (CI/CD) environment for almost any combination of languages and source code repositories using pipelines, as well as automating other routine development tasks. While Jenkins doesn’t eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself.

“Don’t break the nightly build!” is a cardinal rule in software development shops that post a freshly built daily product version every morning for their testers. Before Jenkins, the best a developer could do to avoid breaking the nightly build was to build and test carefully and successfully on a local machine before committing the code. But that meant testing one’s changes in isolation, without everyone else’s daily commits. There was no firm guarantee that the nightly build would survive one’s commit.

Install and Configure Jenkins on Centos7

Step:1 Add Jenkins Repository

Jenkins package is not available in the default Centos7 repositories. So we need to add the Jenkins repository using the given below commands.


[root@jenkins ~]#wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo

[root@jenkins ~]#rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key

Step:2 Install Jenkins and Java

Run the below yum command to install Jenkins and java.

[root@Jenkins ~]# yum install Jenkins java-1.8.0-openjdk –y

Step:3 Start and Enable Jenkins Service

Run the following systemctl commands to start and enable the Jenkins service

[root@jenkins ~]# systemctl start jenkins

[root@jenkins ~]# systemctl enable jenkins

Step:4 Open the ports (80 and 8080) in the OS firewall.

In case the firewall is enabled on your Linux server then run the following commands to open Jenkins-related ports like 80 and 8080.

[root@jenkins ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent

success

[root@jenkins ~]# firewall-cmd --zone=public --add-service=http --permanent

success

[root@jenkins ~]# firewall-cmd --reload

success


Step:5 Access the Jenkins Web portal

Access the URL: http://:8080



The admin password is created and stored in the log file  “/var/log/jenkins/jenkins.log“. Run the below command to get the password.

[root@jenkins ~]# grp -A 5 password /var/log/jenkins/jenkins.log



Copy the password and paste it in the above windows and click on Continue...

In the next windows select the option: Install suggested plugins




As we can see required plugin installation is in progress for Jenkins. Once it is done with plugin installation. It will ask to create Admin User


Click on Save and Finish


Click on “Start using Jenkins”

How to Install GitLab Plugin in Jenkins

Following is a step by step process on how to Install the GitLab plugin in Jenkins:

Step 1: Click on the Manage Jenkins button on your Jenkins dashboard and Click on Manage Plugins:




Step 2: In the Available Page




Select the GitLab, GitLab API, GitLab Authentication, GitLab Hook plugins
Click on Install without restart. The plugins will take a few moments to finish downloading depending on your internet connection, and will be installed automatically.
You can also select the option Download now and install after the restart button. In which plugin is installed after the restart
You will be shown a "No updates available" message if you already have the GitLab plugin installed.

Jenkins Integration with GitLab Webhook

Step 1: Log in to the Jenkins portal, Go to Jenkins dashboard click New item



Step 2: Select the Freestyle Project and Specify the name as per your setup and click OK.





Step 3: In the Build Triggers part copy the GitLab webhook URL




Step 4: Next click the advanced button and Generate a secret token





Step 5: Log in to GitLab and Click your project Repository go to settings ->integrations




Then Click Go to webhook





Step 6: Paste the  Jenkins GitLab webhook URL and Secret token on the GitLab webhook setting page.




step 7: Go to Jenkins Web Portal Click Apply & Save

 




step 8: Then go to the GitLab web portal  Click  Add webhook. After add webhook click the Test button select Push events and it should succeed.




step 9:  if any code commit is done in the GitLab repository, the GitLab code will be triggered and built automatically in Jenkins.



Continuous Integration[CI] and Continuous Delivery[CD]

Continuous Integration (CI) – Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early. By integrating regularly, you can detect errors quickly, and locate them more easily.

Examples of vendors and tools: Jenkins, Teamcity, TravisCI, CircleCI

Continuous Delivery (CD) – Continuous Delivery is the ability to get changes of all types including new features, configuration changes, bug fixes, and experiments into production, or into the hands of users, safely and quickly in a sustainable way. We achieve all this by ensuring our code is always in a deployable state, even in the face of teams of thousands of developers making changes daily.

Examples of vendors and tools: Jenkins, Teamcity, TravisCI, Electric Cloud, Go, Codeship, AWS CodeDeploy


Configuration Management Tools

Terraform

Terraform is an open-source infrastructure as a code tool by HashiCorp. It codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

SaltStack

SaltStack is an open-source configuration management software and remote execution engine. It pulls developers to code and configuration information from a central code repository and pushes that content remotely out to servers. Its primary differentiator is speed, as its multithreaded design enables the execution of hundreds or even thousands of simultaneous tasks.

Ansible

Ansible by Red Hat is a configuration management and provisioning tool that automates cloud provisioning, configuration management, application deployment, and intra-service orchestration. The idea is to automate repetitive IT tasks to allow teams to work on more strategic objectives.

Chef

The chef is a configuration management tool for dealing with machine setup on physical servers, virtual machines, and in the cloud. It helps developers and IT operations professionals to work together to deploy applications on IT infrastructure.

Puppet

Puppet is an open-source systems management tool for centralizing and automating configuration management. It provides an automatic way to inspect, deliver, operate, and future-proof infrastructure and software, no matter where it runs. It is commonly used by DevOps organizations to automate server setup, program installation, and system management.


CI/CD workflow:



CI/CD workflow explanation :

* A developer commits code changes to GitLab.
* Gitlab webhook triggers a Jenkins job. Jenkins pulls a code from the commit happened branch from GitLab. The next stage, Build will happen in this stage, and Jenkins archive a build package.
* Next stage is sonarqube code quality, In this stage, sonarqube checks duplicated code, coding standards, code coverage, code complexity, detection bugs, code smells, and security vulnerabilities.
* if sonarqube code quality fails mail trigger to the developer with sonarqube stage fails reason. otherwise,  Jenkins moves next stage, previously archive build package will be pushed to jfrog artifactory, Jfroge stores binary files version-wise.
* Next stage is deployment, Jenkins triggers an ansible tower job. In this ansible job, It will install java and set java environment and install tomcat server on nodes (centos, ubuntu, windows). After that, pull the latest binary file from jfrog artifactory and deploy that binary file in the tomcat server.
* Whenever a developer commits a code changes to the GitLab it automatically triggers the Jenkins job and it pulls the code from GitLab and builds the code and deploys its server continuously.

 



Relevant Blogs:

What is DevOps?   

Docker build in pipeline  

Terraform execution in pipeline 

Zabbix Custom scripts

Recent Comments

No comments

Leave a Comment