Continuous Integration With Jenkins & GitHub
Hello Everyone, Welcome to my MediumPage!! In this article I would like to do a demo project on Continuous Integration with Jenkins and GitHub.
Jenkins: Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.
Prerequisite:
- Jenkins install
- Knowledge on GiHub, Git and basic Python
For Jenkins Installation and Jenkins Setup, please see the attached link Jenkins documentation.
Let’s start to create a Jenkins job. I have created a Git repository and named it Jenkins-CICD-Pipeline. Inside that folder I have created an app.py python file. Inside the app.py file please type the below simple scripts for our Jenkins project:
def my_function():
print(“Hello from Jenkins ”)
print(“……………………………”)
my_function()
Attached is the snapshot shows the sample repository.
Step 1: Click on ‘New Item’ to create a new Jenkins job.
First, open a browser, navigate to your Jenkins URL, and log in using your Jenkins user name and password.
Then, on the Jenkins Dashboard, click the New Item option on the left-hand side menu.
Step 2: Enter the name of Jenkins job, Choose ‘Freestyle project’ and Click ‘OK’.
Step 3: Enter Job Description if necessary(Optional).
Step 4: Please select Source Code Management as ‘Git’ and paste the Git Repository URL on the Repository URL box.
Step 5: Scroll down to the Build Triggers section and check the Poll SCM see the attached screenshoot here 👎
Note: schedule is given as ‘* * * * *’ which means to schedule trigger for every minute.
Now the Job checks Git repository once every minute for changes and triggers Build if any changes made in the Git repository.
Step 6: Now Under Build, Choose ‘Execute Windows batch command’ if you were running Jenkins in windows environment, select ‘Execute shell’ if you were running Jenkins in Linux environment. I am using Executive shell as I am on a mac os.
Step 7: Enter the commands for the build and click save.
The Jenkins project is created now.
Final Step: Continuous Testing Using Jenkins
Now let’s commit into the repository. Here ‘app.py’ file is changed and committed.
Jenkins Build automatically triggered on code commit.
The output is displayed on the console output like below.
Note: As you see my console output didn’t print the print statement, I did little research on it (url in the bottom on the reference section). Then I figured out a way. I put the below script on the Build stage in Execute shell
#! /bin/sh
python3 -u app.py
Then I see the following output on the console that prints my print statement successfully on the console.
Learning from the error:
- When I run build the project I see the attached error
- After doing little research, my finding was the git repo I had, name was */master but actually the git branch name was */main. Then finally I changed the git branch */name into main instead of */master.
Then observe the auto trigger build successfully the build stage.
Conclusion
In this tutorial, I showed, how Continuous Integration works in Jenkins, and how to troubleshoots on Jenkins.
Thank you everyone 😃, for reading my blog!!
Stay Tuned for my next project!!
👏👏👏👏 Happy Learning!!
If you think, this article is helpful 😄, please give me a clap 👏 👏👏👏 to inspire me. If you need help with Jenkins CI-CD pipeline please see the attached link here.
Please connect me on linkedin 👎
https://www.linkedin.com/in/aktersabina122/
Please follow me on Medium and Twitter 👎: