Scheduled tasks in JIRA are a good way to make sure all such operations happen at quite times, midnight for example. In this post we will write a real simple scheduled tasks and see how easy that can be!
package com.jtricks;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class JTricksScheduledJob implements Job{
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Running the job at "+(new Date()).toString());
}
}
As you can see, the only thing we need to do here is to implement the execute method. Whatever we do in the method can be as simple as the above one liner or as complex as initiating a nuclear explosion!
The next task is to let JIRA know of our new task that we have written and also define the schedule for it. For that, we first need to create a jar file with the above class and drop it under the WEB-INF/lib folder of your JIRA installation. Note that it is not a v2 plugin and hence dropping it under JIRA_HOME/plugins/installed-plugins won't work.
JIRA stores the schedule tasks information in the scheduler-config.xml file under WEB-INF/classes folder. We need to define the schedule for our new task in the same file. First we need to define a job under the jobs tag as shown:
<trigger name="JTricksJobTrigger" job="JTricksJob" type="cron">
<expression>0 0/2 * * * ?</expression><!-- run every 2 minutes -->
</trigger>
The above trigger schedules the job to run every 2 minutes. Lot more details on writing a cron expression can be found here. And that's it! The scheduled job is ready to run. All we need now is to restart JIRA.
Once JIRA is restarted, the new job can be seen at the scheduler details page under Administration > Scheduler Details. We can also verify the next fire time for the task in the same page as shown in the below picture.

scheduled-task-plugin.zip |