Sunday, September 4, 2011
Custom Actions - Exporting Worklogs (part 2 of 2)
In the previous post, I gave a couple of examples of customizing the Worklog Assistant context menu items to script actions for a given issue. In this post, I'm going to talk about how to export JIRA worklogs using the same functionality. Geek credentials are still recommended, by the way.
At the moment, Worklog Assistant only stores worklogs for the current user to simplify storage requirements. So when we are talking about exporting worklogs, we are talking about exporting them only for you.
The general algorithm for exporting worklogs goes is as follows:
script = getUserScript()
worklogs = getWorklogsForDisplayedPeriodInTimesheet()
for worklog in worklogs:
if not worklogHasBeenExportedByScript(worklog,script):
env = getEnvironment(worklog) # also issue
executeScript(script,env)
The key things about this algorithm:
- You have to choose the script you want to use.
- Worklogs are only exported for the displayed time period.
- A worklog is only exported if it has not already been exported by this script.
So let's define a custom script that creates a new file: ~/worklogs.csv. The script defined here will work on Mac and Linux so Windows users will have to translate. What we want to do is create a report that collects all our worklogs for a given time period.
The script itself is quite simple and is shown below:
if [ ! -f ~/worklogs.csv ]; then
echo "Key,Summary,Start date,Time spent (seconds)" > ~/worklogs.csv
fi;
cat >> ~/worklogs.csv << END_WORKLOGS
${JIRA_Key},${JIRA_Summary},${JIRA_WorklogStartDate},${JIRA_WorklogTimeSpentInSeconds}
END_WORKLOGS
If we add this to our custom script configuration, this time changing the type to "Worklog Export", it should look something like this. I named it "Export to CSV":
To use this new script:
- Navigate to the "Timesheet" tab.
- [Optional] Import -> Import Worklogs. I like to use the query "jql: updated >= -4w" to make sure I have the latest data.
- Export -> Export worklogs using custom scripts
- Choose "Export to CSV"
Your file will be located at ~/worklogs.csv. Open it now. You should see all the worklogs for the issues you worked on that week, along with the worklog comments.
Try exporting and reopening the file again. You will notice that the file has not changed. This is deliberate. When Worklog Assistant exports a worklog, a note is made that the worklog has been exported. This way, if you are exporting worklogs for reporting purposes, you do not need to worry about accidentally including double entries.
If you would like to delete the notes on exported worklogs, navigate to:
- Windows: %APPDATA%\Worklog Assistant for JIRA
- Mac: ~/Library/Preferences/Application Support/Worklog Assistant for JIRA
- Linux: ~/.config/Somani Software/Worklog Assistant for JIRA
Then, navigate to the "Exported Worklogs" directory and delete the "Export to CSV" folder. That will get rid of the notes and you can run the script again.
Just as before, there are a set of available fields for each worklog. For convenience, I've included the list as well as example values below.
JIRA_Assignee=sohail
JIRA_Created='Tue Dec 30 17:56:26 2008'
JIRA_Description=-
JIRA_Due_date=
JIRA_Global_Rank=46
JIRA_ID=10124
JIRA_Key=TRACKER-51
JIRA_Original_estimate=0m
JIRA_Priority=Major
JIRA_Project=TRACKER
JIRA_Remaining_estimate=0m
JIRA_Reporter=sohail
JIRA_Resolution=
JIRA_Status='In Progress'
JIRA_Summary=Blogging
JIRA_Time_spent='40h 1m'
JIRA_Type=Task
JIRA_Updated='Sun Sep 4 23:15:24 2011'
JIRA_Votes=0
JIRA_WorklogAuthor=sohail
JIRA_WorklogComment=
JIRA_WorklogCreated='Sun Sep 4 12:27:55 2011'
JIRA_WorklogGroupLevel=
JIRA_WorklogID=14933
JIRA_WorklogIssueID=10124
JIRA_WorklogRoleLeveLID=
JIRA_WorklogStartDate='Sun Sep 4 11:28:08 2011'
JIRA_WorklogStartDate_TimeT=1315150088
JIRA_WorklogTimeSpent='1 hour'
JIRA_WorklogTimeSpentInSeconds=3600
JIRA_WorklogUpdateAuthor=sohail
JIRA_WorklogUpdated='Sun Sep 4 12:27:55 2011'
That's all for custom scripts for now! Please feel free to contact me at support@worklogassistant.com or comment below if you have any questions!
Custom Actions - Adding Menu Actions (part 1 of 2)
You have been warned.
Custom Scripts
Custom scripts in Worklog Assistant are a set of commands interpreted by your computer to accomplish some goal. The general workflow of a custom script is:- Workog Assistant sets up a bunch of environment variables depending on the task you're trying to accomplish.
- Your script is called using the operating system's command interpreter.
- If your script returns with a non-zero exit code, Worklog Assistant assumes that the script failed.
- Menu actions.
- Worklog export.
Adding Menu Actions
- Go to Worklog Assistant's configuration dialog (⌘+, on Mac, Application->Configuration otherwise).
- Choose the "Custom Scripts" tab and click "Add". Mine is pictured below:
- Select the "New script" entry and change the text in the Description field to "Hello World"
- Leave the "Type" as "Context Menu"
- Type in the following in the "Script" section:
- Windows: echo Hello World %JIRA_Summary% && exit 1
- Mac/Linux: echo "Hello World ${JIRA_Summary}" && exit 1
- It should now look like the following
- Click "Save"

If you then click on the "Hello World" entry, you should see the following dialog:

And there you have it! You have created a custom menu action. To find out all the variables that are available to you, you can use the following custom script:
- Windows: (set | findstr JIRA_) && exit 1
- Mac/Linux: (set | grep JIRA_) && exit 1
Change the "Hello World" script to the following:
open "http://www.google.com/search?q=${JIRA_Summary}&sclient=psy&hl=en&noj=1&site=webhp&source=hp"This script searches Google for the summary of your JIRA issue when clicked! Note that I did not include the "exit 1" because I don't want Worklog Assistant to assume the custom script failed.
In the next part, I'll talk about utilizing the same custom scripts workflow to export your JIRA time tracking information.
Update: For convenience, I've included the main environment variables below along with sample output. The full list can be found here.
JIRA_Assignee=sohail
JIRA_Created='Tue Dec 30 17:56:26 2008'
JIRA_Description=-
JIRA_Due_date=
JIRA_Global_Rank=46
JIRA_ID=10124
JIRA_Key=TRACKER-51
JIRA_Original_estimate=0m
JIRA_Priority=Major
JIRA_Project=TRACKER
JIRA_Remaining_estimate=0m
JIRA_Reporter=sohail
JIRA_Resolution=
JIRA_Status='In Progress'
JIRA_Summary=Blogging
JIRA_Time_spent='36h 50m'
JIRA_Type=Task
JIRA_Updated='Sun Sep 4 15:39:52 2011'
JIRA_Votes=0
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