Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Exporting list of ScriptRunner jobs

In ScriptRunner for Jira, I've been programming various Jobs in ScriptRunner, which recursively create Jira tasks, with a frequence defined by each Job's cron expression.

They work fine, but we find it hard to manage them. For instance, we would like to check which Jobs are going to execute within the coming weeks, or to review the whole list to make sure nothing's missing.

The list provided in the ScriptRunner interface doesn't fulfill our need:

  • it only states the name of the Job and its next occurrence time -- not its periodicity or its creator
  • you need to be administrator of the instance in order to consult it

Q.: Is there a way to export a list of all such Jobs that are defined within the Jira instance, including their name and periodicity?

If such a list could be automated, it would be even better!


1 answer

0 votes

You would need to query the database directly.

You can use scriptrunner resources to access the DB and scriptrunner custom REST Endpoint to provide a way for non-admin to view this data.

Something like this:

import com.onresolve.scriptrunner.db.DatabaseUtil
import groovy.json.JsonSlurper
import groovy.transform.BaseScript


@BaseScript CustomEndpointDelegate delegate

getJobs(httpMethod: "GET", groups: ["jira-users"]) { MultivaluedMap queryParams ->
def jobJson = DatabaseUtil.withSql('local_jira'){sql->
def q = /Select t.setting From AO_4B00E6_STASH_SETTINGS t Where t.KEY = 'scheduled_jobs'/
def rawJobs = new JsonSlurper().parseText(jobJson)
//here I convert the rawJobs into a list with field names that might be easier for users and I can exclude some of the parameters
def retJobs = rawJobs.collect{rawJob->
def retJob = [:]
retJob.note = rawJob.FIELD_NOTES
retJob.interval = rawJob.FIELD_INTERVAL
retJob.schedulteType = rawJob.scheduleType
retJob.jobType = rawJob['@class'].tokenize('.').last()
retJob.jql = rawJob.FIELD_JQL_QUERY
retJob.wfaction = rawJob.FIELD_ACTION
retJob //return the new map
return Response.ok(retJobs).build()

Hi @Peter-Dave Sheehan,

Many thanks for the answer! I may be able to try it out before I leave for vacation, but I'm not a pro with ScriptRunner and may need help from a colleague (who is in vacation now!) when I return.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

947 views 2 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you