Open In App

How to Build Python Application Using Jenkins ?

Last Updated : 16 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Jenkins is one of the most popular automation tools used worldwide for Continuous Integration and Continuous Delivery. It is a free and open-source automation server that enables developers to build, integrate and test the code automatically as soon as it is committed to the source repository. Building a Python application utilizing Jenkins includes setting up an automated interaction for tasks, for example, getting the source code, running tests, and producing artifacts like executables or sending bundles. Jenkins, an open-source automation server, works with this by giving a stage to define, plan, and execute such tasks consequently.

What Is Jenkins?

Jenkins is one of the most popular automation tools used worldwide for Continuous Integration and Continuous Delivery. It is a free and open-source automation server that enables developers to build, integrate, and test the code automatically as soon as it is committed to the source repository.

Jenkins is a Release phase tool. It provides automated build, automated tests, and automated Continuous Integration Continuous Delivery , ability to install Jenkins Locally, plugins etc....

Primary Terminologies Related To Application Build Using Jenkins

  • Pipeline: Jenkins Pipeline is a set-up of modules that upholds the automation and joining of programming delivery pipelines. Pipelines can be characterized utilizing a text-based DSL (Domain Specific Language) in a Jenkinsfile, considering the meaning of complex work flow as code.
  • Jobs: Jobs in Jenkins address individual tasks or cycles that Jenkins executes. Jobs can incorporate build, testing, sending, and other computerization tasks/errands. Jenkins gives different kinds of jobs, for example, Free-form projects, and Pipeline projects.
  • Build: A form in Jenkins refers to the most common way of gathering, testing, and package of programming/software artifacts. Jenkins triggers assembles in view of events like code commits, planned times, or manual triggers. Build artifacts can include executables, libraries, documentation, and different records produced during the form interaction.
  • Plugins: Jenkins highlights a rich environment of modules that expand its usefulness. Modules can coordinate Jenkins with version control systems, build-systems, testing systems, deployment stages, and different administrations and devices. Clients can install and arrange modules to modify and upgrade Jenkins as indicated by their particular necessities.
  • Nodes: Nodes in Jenkins address individual machines (or specialists) where Jenkins can execute jobs/Tasks. Node can be master node (where Jenkins is introduced and made due) or specialist node (where constructs are executed). Jenkins can distribute jobs across various nodes to parallelize build and further develop execution.
  • Master: The Jenkins Node is the main server case liable for dealing with the design, planning, and execution of construct jobs. It has the Jenkins web connection point and organizes the communication between clients, jobs, and agent nodes.
  • Workspace: A work area in Jenkins is a registry on the agent or master node where Jenkins looks at source code and executes build jobs. Each build jobs has its own workspace/area directory/registry, where it performs tasks and stores impermanent records produced during the process.
  • Triggers: Triggers in Jenkins are conditions or events that start the execution of build job. Triggers can includes code commits to the version control systems, changes in setup, planned schedules, manual triggers by clients, or upstream work completion.

How To Build Python Application Using Jenkins: A Step-By-Step Guide

Step 1: Launch An Instance

  • Launch an EC2 Instance with the required specifications or with the following specifications: AMI as Amazon Linux 2-kernel 5.10 SSD volume, Instance type as t2.micro, Select existing Key Pair ( if there is no key existing key-pair, create new one), security Groups with port number 22 and 80, and allow configured port numbers.
Launching An Instance

Step 2: Connect To Instance Using SSH

  • With the help of SSH Command, connect the instance with the terminal.
ssh -i "key-pair" ec2-user@publicIPaddress
Connecting To Instance Using SSH

Step 3: Install Git In Instance

  • With the help of the below command, install git package into the instance.
sudo yum -y install git
Install Git Instance

Step-4: Install Java Software

  • Install Java-17 version as run time and install Jenkins.
  • With the help of below command, install run time and Jenkins service.
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
# Add required dependencies for the jenkins package
$ sudo yum -y install java-17*
sudo yum install jenkins
sudo systemctl daemon-reload
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins
Install and Starting Jenkins Server

Step 6: Login To Jenkins Server

  • Login to the Jenkins official page by copy and paste the instance Public IP address along with port 8080.
Login To Jenkins Server

Step 7: Create A Jenkins Job

  • Create a new item, give description, in the execute shell give commands to clone the GitHub repository and application to be host.
Creating A Jenkins Job
  • This github URL "https://github.com/chintuu77/fish" contains the application code.

Note: If the Repository is public, we can clone the repository without giving any credentials. If the repository is private, we have give GitHub credentials. i.e. PAT (Personal Access Token)

Step 8: Steps To Create Password Authentication ( Optional )

  • Got to the GitHub account and navigate to settings. Under settings there is a option called Developer Settings.
Developer Settings in GitHub  Account
  • Under Developer Settings, select Personal Access Token (Tokens classic).
Generating PAT
  • Click-on Generate new token (classic). Give Token name and select scopes, which are nothing but access to the personal tokens.
PAT creation
  • Then, click on generate token.
Sucessfully created the PAT
  • If the GitHub repository is private while cloning, it will ask you user name of the GitHub account and password. Give user name and in place of password provide this created PAT (personal access token).

Step 9: Save Created Job And Build It

  • After clicking build now, wait until the job got finished and see the console output for the result.
Succcessful Build Of Python Application

Step 10: Now, copy and Paste the Public Ip of the instance along with port 2000 to see application hosted.

  • Why we are browsing the public IP along with port number as we define it in the meta data file.
META DATA file - app.py
  • Copy the public IP address of the instance.
    Listing The Instances
  • Now, paste the copied IP address ad browse it along with port number which is assigned in the meta data file. Here we assigned 2000 port number.
successful deployment of Python application

Conclusion

By utilizing Jenkins pipelines and jobs, designers can initiate work processes that flawlessly coordinate with version control systems, automate testing processes, and guarantee dependable conditions.

By embracing Jenkins for building Python applications, groups can accomplish more reliability, efficiency, and versatility/scalability in their development processes. All in all, building a Python application using Jenkins offers a smoothed out and automated way to deal with programming development, testing, and deploying.



Next Article
Article Tags :

Similar Reads