Skip to main content

Schedule Builds

Updated May 15, 2020 ·

Lab Environment

In this lab, we have the following Linux machines, and we will use a local computer (laptop) to connect to them.

  • jenkinsmaster

You can choose to set up a virtual machine on your computer or create instances in the cloud. In this case, EC2 instances are used.

Note that for this lab, we'll only be using jenkinsmaster and you can disregard the other tstsvrs and jenkinsslave1 for now.

Setting Up Jenkins

If you have your Jenkins server already setup, you can skip this section. There's an option to manually install Jenkins on a Linux machine or you can also use Ansible playbooks to perform the entire installation of Jenkins on this machine.

To setup Jenkins:

Using Scheduled Builds

When to use Scheduled Builds?

  • For very long running build jobs.
  • For jobs where quick feedback is less critical
  • For intensive load and performance tests which may take hours.

Install the Plugin

For this one, we need to install the Schedule Build plugin from the Manage Jenkins > Manage plugins > Available

Next, create a new folder Test-Builds and a new job called local-log-viewer.

In the Build section, click the dropdown bar and select Execute shell. In the Command field, enter:

sudo cat /var/log/messages 

Hit Save afterwards. Back in the Project page, click the Schedule Build in the left panel.

In the date field, I entered a date/time that will trigger the job after 2 minutes.

In the Build history in the left panel, you should see how much time is remaining before the job is triggered.

Once it's done, you should be able to click the build and see the console output.

Now this is good if we just want a build to occur one time. If we want the build to be triggered in some particular intervals, like for example, every midnight, we can set up a "cron-based" schedule.

Setup a Schedule

To schedule the build, click Configure on the job and go to Build Triggers > Build periodically. Then put the cron syntax in the Schedule field.

In th example, above, we want to run the job every 2 minutes so we used this cron syntax:

H/2 * * * *