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:
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
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()
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.