How to Schedule a Jenkins Job to Run Every Day at 12 AM

Spread the love

Automating tasks is a crucial part of DevOps and continuous integration/continuous deployment (CI/CD) practices. Jenkins, a popular automation server, allows you to schedule jobs at specific times using cron-like syntax. In this article, we’ll walk you through the steps to schedule a Jenkins job to run every day at 12 am.

Why Schedule Jenkins Jobs?

Scheduling jobs in Jenkins can be highly beneficial for various reasons:

Automated Backups : Schedule backups of your databases or critical files.

Nightly Builds : Ensure your software builds every night, catching integration issues early.

Maintenance Tasks : Automate routine maintenance tasks like cleanup scripts or performance monitoring.

Step-by-Step Guide to Scheduling a Jenkins Job

1. Open the Job Configuration

First, navigate to your Jenkins dashboard and open the configuration page of the job you want to schedule.

2. Configure Build Triggers

Scroll down to the “Build Triggers” section. This section allows you to specify when your Jenkins job should run.

3. Enable Periodic Builds

Check the box labeled “Build periodically.” This will open a text box where you can enter your scheduling information using cron syntax.

4. Enter the Cron Schedule

To schedule the job to run every day at 12 am, enter the following cron expression in the text box:

Understanding the Cron Expression

The cron expression 0 0 * * * means:

– 0 : The minute (0th minute)

– 0 : The hour (12 am)

– * : Any day of the month

– * : Any month

– * : Any day of the week

So, this expression schedules the job to run at 12:00 AM every day.

See also  How To Install Jenkins on Ubuntu 20.04

5. Save the Configuration

After entering the cron expression, scroll down and click the “Save” button. Your job is now scheduled to run every day at 12 am.

Example: Jenkins Pipeline Script

If you’re using a Jenkins pipeline, you can include the cron syntax directly in your pipeline script. Here’s an example:

pipeline {
	agent any

	triggers {
    	cron('0 0 * * *')
	}

	stages {
    	stage('Example Stage') {
        	steps {
            	echo 'This job runs every day at 12 am'
            	// Add your build steps here
        	}
    	}
	}
}

In the above example, the `triggers` block contains the cron syntax to schedule the job at 12 am every day. You can customize the stages and steps according to your specific requirements.

Conclusion

Automating your Jenkins jobs to run at specific times can save you a lot of manual effort and help maintain consistency in your development and deployment processes. Whether it’s for nightly builds, backups, or routine maintenance, scheduling your jobs efficiently ensures that essential tasks are executed without fail.

By following the steps outlined in this article, you can easily configure your Jenkins jobs to run at 12 am every day. Happy automating!

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com