You are currently viewing Mastering CI/CD: A Comprehensive Guide to Building Jenkins-GitHub Pipelines

Mastering CI/CD: A Comprehensive Guide to Building Jenkins-GitHub Pipelines

Step-by-Step Guide: Creating and Deploying a Freestyle Jenkins Project for Efficient Software Development2

Boost Your DevOps Efficiency with Jenkins: Say Goodbye to Manual Server Updates

Picture this: Your hardworking team is dedicated to delivering new features promptly, but the process of transitioning code from development to testing and production is a tedious task. Manually pulling code from version control, running tests, and ensuring a smooth deployment can be time-consuming and error-prone. As the frequency of commits increases, developers find themselves repeating this server update process over and over again. Discover how Jenkins can revolutionize your workflow, automating server updates and streamlining your DevOps pipeline.

Here’s a manual way to update servers:

  • SSH into the server.
  • Pull from VCS.
  • Check configs before starting the app.
  • Start app in containers.
  • Check logs and make sure app is running.
  • End SSH session.

So, how to automate this process? Enter the paradigm of Dev Ops, Dev Ops focuses on making the cycles of development and operations compatible with each other, it tries to bind them both together. Jenkins is a CI/CD Dev Ops tool built in Java.

As mentioned in the title, we are going to see how Jenkins can help us eliminate this manual process and automate the entire flow.

Prerequisites
Before getting started with our recipe let’s get our ingredients straight.

This tutorial is going to use Jenkins installed on local machine, in case you are doing it on a remote computer replace localhost by your computer IP

Firstly, Jenkins needs to be installed on the computer you are trying to deploy on, installation instructions here: https://www.jenkins.io/doc/book/installing/. Secondly, this demo is going to use docker so if you want to follow along install docker on your system, guide: https://docs.docker.com/engine/install/.

Lastly, we need a project repository set up on a VCS like GitHub.

Post Installation Steps
Once Jenkins installation is completed, go to http://localhost:8080 and a screen will appear asking you to unlock Jenkins. To set up your user, which is a mandatory process, follow this guide: https://www.jenkins.io/doc/book/installing/linux/#setup-wizard

Creating Jenkins Project
Jenkins has 2 types of projects, Freestyle and Pipeline. The major difference in both is that pipeline projects follow a particular flow and can have multiple agents and stages to build, test and deploy the project. Freestyle project is easy to set up and get started with. Now let’s start with our project configuration.

After you are logged in, you will see a screen like this. This is the Jenkins home page or dashboard, here a user can see all the pipelines created and a summary of the pipeline.

jenkins codeacademia


Here, we have to click on New Item at the top left, following this, enter a name for your project, click on Freestyle project and hit OK

jenkins
jenkins

The next step is to configure our project with VCS information, I am going to use GitHub as a VCS. Tick GitHub project and and enter the repository URL.

jenkins

Scroll down a little and we can see a Source Code Management form asking for the credentials to log in to VCS and the branch to use. In case of a fresh installation, credentials need to be added to Jenkins, to do this click on the Add button, enter your username and password click on Add.

jenkins

Now we enter in the section of Build Triggers, here we set triggers which will tell Jenkins when to build a project. The most common and efficient way to do this is by using web-hooks.

Web hooks allow interaction between web-based applications through the use of custom callbacks. The use of web-hooks allows web applications to automatically communicate with other web-apps. A web-hook is set to trigger when a certain event occurs.

In our case, the event which will trigger the webhook is going to be a push action to the remote repository. We are not going to use webhooks in this tutorial instead we will be using the Poll SCM option, what this option does is that it continuously queries the VCS, based on a predefined schedule, for new changes. If new changes are encountered then Jenkins will start the project build steps.

The predefined schedule used here is * * * * * which is a time schedule for every minute, Jenkins uses a syntax similar to Crontab, explore the format on crontab.guru.

jenkins

The only step remaining is to write the build commands to do so head over to the Build section and write your docker build and run commands in detached mode.

jenkins

We are done setting up our project, the last step is to click Save at the bottom of screen and start the first build by clicking on the Build Now button.

jenkins

On a successful build, the build number will show a green tick icon and your app will be published on specified port of defined network, in our case, the app will go live on localhost:3000. You can check the console output for the build process by clicking on the drop down beside the build number.

jenkins

With the help of this console output, a user can debug the build process.

Conclusion
Hope you were able to follow along and successfully complete your first build. I will be more than happy to answer your doubts in the comments. Thanks for reading! Stay in touch for more such tutorials on automation and python projects.

Leave a Reply