Custom Scheduled Jobs
You can use this option to create your own scheduled jobs to run code at regular intervals. To create a custom scheduled job, follow these steps:
- Add a Note for your own reference.
- Select a User who the code will run as.
Enter how often you want the job to run on Interval/Cron Expression.
Select Show Examples for example time periods.- Add Inline Script to tell your job what to do. You can enter the code on Script or choose existing code on File.
- Select Add to schedule your job or Run Now to execute the script now.
Example: Delete Old Comments Once a Month
If you find that you have a lot of old comments on Confluence pages, you can delete these at a regular interval using a custom scheduled job by following these steps:
- Enter
Delete Old Comments Monthly
for Note. - Select Admin for User.
- Enter
0 0 0 ? 1/1 MON#1 *
for Interval/Cron Expression to run at 12:00 AM on the first Monday of the month. Enter the following code for Inline Script.
groovydef olderThan = "4w" def deletedComments = 0 def oldComments = get("/wiki/rest/api/search") .queryString("cql", "type=comment and lastmodified < now('-${olderThan}')") .asObject(Map).body.results oldComments.each { def contentId = it.content.id def response = delete("/wiki/rest/api/content/${contentId}").asString() if (response.status == 204) { logger.info("Successfully deleted comment with id: {}", contentId) deletedComments++ } else { logger.error("Error Status: {} - Failed to delete comment {} for page with id {}", response.status, it.title, contentId) } } logger.info("Successfully deleted {} comments ", deletedComments)
- Select Add.