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

How to create a cron service or subscription in jira plugin

dhaval soni
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.
February 5, 2013

I want to create a service in jira which would evalute work log and generate user's time sheet report and daily send it to specific email address.

Can any one tell me, how such chron or subscription would be possible in jira plugin development ?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Midori
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.
January 27, 2015

If you don't want to create a custom plugin just for this (which would be a great exercise otherwise), then develop a template for the PDF View Plugin and email the timesheet daily with the PDF Automation Plugin.

You could use the "timesheet-fo.vm" template as a starting point for your custom template. It gives access to both "plain vanilla" JIRA worklogs and Tempo worklogs.

See this time-based invoice generated from worklogs as an example

0 votes
Henning Tietgens
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.
February 5, 2013

You can use Script Runner plugin to create a service which runs every x minutes. Within the service you could restrict the execution to specific time frames.

Henning

Henning Tietgens
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.
February 5, 2013

I use this little piece of code for our services.

import org.apache.log4j.Logger
import static java.util.Calendar.HOUR_OF_DAY
import static java.util.Calendar.MINUTE

// *** Configure parameters for the service here ***
hourOfDay = 0..0
minuteOfDay = 45..46
logClass = 'MyClassName'
myName = 'My Service'

// *** Define functionality of service here ***
void runService (String myName, Logger log) {
}

// *** Don't change anything below this line ***

rightNow = Calendar.getInstance()
Logger log = Logger.getLogger(logClass)
if (hourOfDay.contains(rightNow.get(HOUR_OF_DAY)) && minuteOfDay.contains(rightNow.get(MINUTE))) {
    log.info "Starting $myName"
    runService(myName, log)
} else {
    log.debug "$myName skipped, it's not the right time now."
}

If you configure such a service to start every 1 minute, this one is started at 0:45 or 0:46.

Henning

Henning Tietgens
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.
February 5, 2013

If you stay with my example within the runService() method. For example we use this to generate a csv file from an SQL statement against the JIRA Database and send this to some internal email recipients.

dhaval soni
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.
February 5, 2013

sorry, just want to ask:

Where would i have to write the - "Report creation" logic in script runner plugin , report will need to evalute and generate in specific template format.

Is it achivable with this script runner plugin ?, i have to write script in jira - script runner plugin editor or , eclipse ?

Henning Tietgens
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.
February 5, 2013

You can write this within your favorite IDE or a text editor. Groovy is similar to Java and e.g. IntelliJ IDEA has nice support for it. In the documentation of the Script Runner plugin are a lot examples and a guide how to configure the IDEA IDE.

Henning Tietgens
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.
February 5, 2013

You just write your groovy script, save it as a file on the JIRA server, add a Script Runner service to JIRA, and connect the grovvy file to it like described here.

dhaval soni
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.
February 5, 2013

In plugin code, where do i have to write this stuff to execute this script as it needs to execute from server itself and automated.

dhaval soni
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.
February 6, 2013

Hi,

Thanks for your comments.

i have installed script runner and able to see under Administrator >> Plugins menu >> script runner menu item.

Now, i want to execute below stuff into the script runner . but this is plugin java stuff and not looks compatible. can you please tell me alternatives or any option to execute.

(stuff.txt)
thanks
Henning Tietgens
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.
February 6, 2013

You can combine your stuff.txt with my source code above if you put all code outside of the methods in your stuff.txt into runService() method and add the methods to my source, Java most of the time is compatible with groovy. After that save it as stuff.groovy on the server and proceed like described above.

But your code depends on an issue and if you like to run it as a service you first have to get a list of issues you want to get the worklog from and you need to do something with the resulting contextMap...

TAGS
AUG Leaders

Atlassian Community Events