Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting list of ScriptRunner jobs

Normand Brousseau June 28, 2021

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!

Thanks,
Normand

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2021

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.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.db.DatabaseUtil
import groovy.json.JsonSlurper
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@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'/
sql.firstRow(q)[0]
}
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()
}

Normand Brousseau June 29, 2021

Hi @PD 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