How to debug scripted post-functions?

Roberto Saltini June 27, 2016

I am currently playing with Script Runner and post-functions.

I would like to know how to improve my debugging workflow.

So far, the best way I have found is

  • Create a "Test" Scripted Field
  • Write my script in the "Test" Scripted Field and debug it by executing it via "Preview" and getting the debug information via Log
  • Copy the script to the scripted post-functions
  • Execute the transition that triggers the post-function
  • Go back to the post-function executing information and verify via the Log tab that everything execute correctly.

The problem with this workflow is that not everything that the context of a post-function is different from the context of a Scripted Field. As a consequence of this, sometimes when I transfer my the script from Scripted Field to post-function I get unexpected errors.

Thereafter, to correct errors in the post-function I found that the following workflow is required

  1. Execute the transition that triggers the post-function
  2. Go back to the post-function executing information and verify via the Log tab that everything execute correctly.
  3. Edit the post-function
  4. Update the post-function
  5. Update the workflow
  6. Repeat from step 1 until the post-function executes correctly

I find this workflow quite time consuming, so I wonder whether a faster debugging workflow for post-function exists.

Thanks

 

3 answers

1 vote
JamieA
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 29, 2016

If you are using script console, you can use:

import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
import groovy.transform.BaseScript

@BaseScript ContextBaseScript baseScript

def issue = getIssueOrDefault("ABC-1")

If it's not running in a workflow function, it will use ABC-1, otherwise whatever the issue is. So you don't need to remember to comment it again.

Mario Carabelli
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 17, 2019

Hi @JamieA,

is there a documentation somewhere what methods your implementation of baseScript includes?

This would be a help in making my scripts more testable in general in the scripting console.

With kind regards
Mario

1 vote
adammarkham
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 27, 2016

You could add logging statements like:

log.warn("useful information")

to see the value of variables and the general execution of the script. However this is quite time consuming for more complex scripts.

If you really want to debug a post-function properly its probably best to do it in a test/staging instance of JIRA, adding the post-function as as a script file. Then follow the instructions here for setting up a development environment in an IDE to allow debugging of the script.

Note that the instructions at that link are not fully up to date but it should get you going with the general approach to take to debugging your script. 

ahmed salem November 12, 2020

Hi,

 

I'm quite new to Jira post functions.

 

After using log.warn("something useful"), where do I get to see the warnings? Not in Console I assume?

0 votes
Vasiliy Zverev
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 27, 2016

I usually use Script console. And I add an issue variable like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("zxcv-1")

After this I comment this line before place it to postfunction.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events