3

On JIRA, how can I restrict a specific status of my workflow to hold only one issue per time?

Because we're automating all our workflow, I want to have a specific status (ACCEPTANCE) that only accepts ONE issue per time. So in our board, no regular user should be able to move a second or more cards to that column while there's one card there.

1

Out of the box, JIRA will let you set issue count as a column constraint in the column settings of a particular agile board's configuration. I don't believe this prevents a status transition, though. It simply uses visual indicators (color of the column) when the issue count meets or exceeds the defined limit.

To actually block it, a condition would have to be added to whatever transitions point to 'Acceptance' in your workflow(s). No native JIRA condition types can do this for you (as of JIRA 7), but there are add-ons that'll help. ScriptRunner and JJupin come to mind, and so does JIRA Misc Workflow Extensions, which adds support for writing groovy script conditions.

Now, I have no skill at Groovy whatsoever, and I break every novice coding rule in the book, but starting from an example in ScriptRunner's documentation for a script that uses JQL, I was able to make something that does work when used as a scripted condition:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// edit this query to suit
def query = jqlQueryParser.parseQuery("project = ABC and status = ACCEPTANCE")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

return (results.total == 0)

(adapted from Execute a JQL Query as of 2016/11/26)

The query can be whatever you want it to be, such that it would return issues in the restricted status. The final line will basically return TRUE only if the query has no results, meeting the terms of the condition and allowing the status transition to appear.

If you want it to be more portable, there's probably a way to retrieve the project key of the current issue and concatenate that into the JQL. But if this is only happening in one project, you can skip the extras.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.