☑️Day 52: Exploring Cron Jobs in Jenkins and Integrating GitHub for Automation🚀
Today’s learning journey focused on two crucial DevOps concepts:
Using Cron Jobs in Jenkins for scheduling tasks
Integrating Jenkins with GitHub to automate builds from repositories.
✅1. Cron Jobs in Jenkins
What is a Cron Job?
A cron job is a time-based task scheduler that automates repetitive tasks at specified intervals (e.g., every minute, hour, or day). It’s widely used in Linux systems but also incredibly useful in Jenkins for automating jobs like backup tasks, cleanup operations, or periodic builds.
Setting up Cron Jobs in Jenkins
In Jenkins, we can define a cron job by specifying the build trigger under "Build Triggers" using the "Build periodically" option. This allows Jenkins to automatically execute a job at a certain time interval.
Task: Automating a Task Every Minute
I configured a Jenkins job to run every minute, performing simple tasks such as echoing a message and creating a directory using the following steps:
Go to Jenkins > Configure the Job.
In Build Triggers, check the box for "Build periodically".
Use the cron expression
* * * * *
to schedule it to run every minute.In the Build Steps, add shell commands like:
echo "Automated task running"
.mkdir -p /var/jenkins_home/devops_task
.
Real-Time Use Cases:
Backup automation: Automating backup of files or databases at regular intervals.
Log cleanup: Scheduling periodic cleanup of logs to free up space.
Status checks: Automating regular checks for service or infrastructure health.
✅2. Integrating GitHub with Jenkins
What is GitHub Integration?
Jenkins can be integrated with GitHub to automate the process of building, testing, and deploying code whenever changes are pushed to a GitHub repository. This helps in continuous integration (CI) by ensuring the code is always tested and built after every commit.
Steps to Clone a GitHub Repository and Build
Step 1: Install the Git plugin for Jenkins if it’s not already installed.
Step 2: Create a new Freestyle Project in Jenkins.
Step 3: In the project configuration, under the Source Code Management section, select Git.
Add the repository URL (e.g.,
https://github.com/username/repository.git
).
Step 4: Configure the Build Steps to run the build process. Since I cloned a simple Python project, the steps involved running the Python script with commands like
python3
script.py
.Step 5: Configure Build Triggers to automatically trigger a build when code is pushed to GitHub (using "GitHub hook trigger for GITScm polling").
After setting up, Jenkins automatically cloned the repository from GitHub and built the Python script successfully.
Real-Time Use Cases:
Continuous Integration: Automatically testing and building the code after every push to the GitHub repository.
Automated Deployment: Jenkins can also be set up to deploy the application to a server once the build passes.
Code Quality Checks: Automating code reviews with tools like SonarQube after every commit.
✅Why These Skills Are Essential in DevOps?
Automation with Cron Jobs: Cron jobs are fundamental to any DevOps workflow, automating repetitive tasks that keep systems running smoothly without manual intervention.
GitHub Integration: Integrating Jenkins with GitHub for CI ensures that teams can continuously build and test their code, catching bugs early and improving code quality.
🚀Thanks for joining me on Day 52! Let’s keep learning and growing together!
Happy Learning! 😊
#90DaysOfDevOps
Subscribe to my newsletter
Read articles from Kedar Pattanshetti directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by