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.
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
Step 3: Install Git In Instance
- With the help of the below command, install git package into the instance.
sudo yum -y install git
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
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.
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.
- 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.
- Under Developer Settings, select Personal Access Token (Tokens classic).
- Click-on Generate new token (classic). Give Token name and select scopes, which are nothing but access to the personal tokens.
- Then, click on generate token.
- 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.
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.
- Copy the public IP address of the instance.
- 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.
How to Build Python Application Using 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. 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.