Check sub-task status in Post-Function and stop from transition if sub-task still in Open status.

Farhan Taib December 5, 2017

Hello,

 

I have added transition in a workflow from status "In Review" to "QA Open". This transition set with option triggers "Automatically transitions the issue when a related pull request is merged".

I noticed that Triggers will ignore Conditions and Validators.

Atlassian support suggest to create groovy script to be add in ScriptRunner in Post Function.

I am quite new in creating this groovy script. Does anyone has script example to check sub-task status in Post-Function and script example to stop from proceed transition.

2 answers

0 votes
Farhan Taib December 6, 2017

Thanks Steve,

As your suggestion, I have created 2 transition.

  1. Transition1 for the trigger which loop back to original state. At the Post Function I use the Fast-track transition and just leave the condition blank as it will assume as true then Action to Transition2. (In this transition I add condition hide transition from user)
  2. Transition2, linked to next state with condition to check sub-task status.

It works like charm :)

Stephen Cheesley _Adaptavist_
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.
December 7, 2017

Glad to hear it worked :-)

0 votes
Stephen Cheesley _Adaptavist_
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.
December 6, 2017

Hi Farhan,

This might be quite straight-forward in your use case. You could use a built-in script called "Fast-track transition an issue" with a condition added to it. That would limit the amount of Groovy that you need to write.

You can find a good example of it in the documentation https://scriptrunner.adaptavist.com/5.2.4/jira/builtin-scripts.html#_fast_track_transition_an_issue

This approach works by transitioning the issue back to its original state rather than "stopping" the transition (hopefully this would work for your use case).

Here is an example of some code that will retrieve the sub-tasks for an issue that you can use in the condition field. You just need to add the condition that you want to check on and return the relevant value (see built-in examples for condition field)

issue.getSubTaskObjects().each{ subtask ->
println(subtask.id)
}

 I hope this helps!

Steve

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events