Tuesday, January 15, 2013

Logging time to sub-tasks only in JIRA using custom scripts

Hello and welcome to another edition of "Stuff you didn't know you could do with Worklog Assistant."

As referenced in a previous post, custom scripts are a nifty way to extend Worklog Assistant to perform issue-specific housekeeping tasks.

For example, I use custom scripts to create and merge branches for a given issue. This is done through a "Context menu" script which allows me to add custom commands to any issue:

One of the recent additions to Worklog Assistant are a couple of new of "hooks" (in the Emacs parlance) or "extension points" (in Eclipse-speak).

The new hooks (can you guess what editor I use?) allow you to run a script when you toggle the timer on an issue and/or run a script once a minute.

People are already using them! Michael van Engelshoven was kind enough to share that he uses the new functionality to generate a git commit template:
With the output looking something like this:
But that's not all! As the title of this post suggests, it is possible to use custom scripts to prevent yourself from accidentally logging work on issues that you should not log work on. For example, against issues that are not assigned to you. In this case, I will show an example of how you can generate an informative message when you unintentionally start logging work against a sub-task.

So a quick review:
  • Custom scripts work by executing platform-native scripts
  • Custom scripts are executed in response to different user interaction (none, explicit, implicit, etc)
  • All properties of the current issue are exposed through environment variables. For example, the summary field of an issue is exposed as the variable JIRA_Summary
  • Scripts that have a non-zero exit code are assumed to have failed and the user is notified.
Putting these together, we might guess as to how to prevent a user from tracking against an issue that is not a sub-task:
  • Create an "Issue Timer Toggle" custom script (the name is horrible, sorry)
  • Detect if the issue is a sub-task
  • If not, the script should fail with an error message
And that is exactly what is done here:

The script is specific to Windows but it can easily be modified for other platforms:

if "%JIRA_IsSubtask%" == "0" (
  echo ---------------------------
  echo %JIRA_Key% is not a sub-task!
  echo ---------------------------
  echo Please choose a sub-task
  exit 1

When I toggle a timer on an issue that is not a sub-task, I am greeted by this message, fully customized by you!

This wraps up another edition of "Cats riding invisible bikes" "Stuff you didn't know you could do with Worklog Assistant." To find out more, check out the documentation on custom scripts. As always, have a nice day and feel free to contact me with any questions, comments or suggestions!

No post is complete without a funny picture of a cat so here is a coder cat:

About this blog

We strongly believe that tracking your time properly is the first step to deterministic software development. If you feel that you have been guessing or you can't be bothered to remember to log time, Worklog Assistant might be for you!

Give it a try!

Please download a free 30-day trial today by clicking on the link below: Download