Direct database update queries are not recommended in JIRA. Instead, we recommend adding or modifying data using JIRA’s APIs (via ScriptRunner). If you absolutely must modify data in your database via direct database queries, always back up your data before performing any modification to the database.
Iam using a groovy script in a transition postfunction to ask the database for the person that did a specific transition in the issue workflow. For that the might exist an api function too but writing the query and executing it was for me the fastest way.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import java.sql.Connection
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.util.ImportUtils
//import com.atlassian.crowd.embedded.api.User
//Issue issue = issue
//def id = issue.getId()
ComponentManager componentManager = ComponentManager.getInstance()
def delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class)
String helperName = delegator.getGroupHelperName("default");
def sqlStmt = """
SELECT a.author as 'doer' FROM changegroup as a JOIN changeitem as b ON b.groupid = a.id
WHERE b.field = 'status' AND a.issueid = ${issue.id} AND b.oldstring = 'In Progress' AND b.newstring = 'Review'
ORDER BY a.created DESC LIMIT 1
"""
Connection conn = ConnectionFactory.getConnection(helperName)
Sql sql = new Sql(conn)
try {
StringBuffer sb = new StringBuffer()
sql.eachRow(sqlStmt)
{
sb << it.doer
}
def userManager = (UserManager) ComponentAccessor.getUserManager()
def user = userManager.getUserByName(sb.toString())
issue.setAssignee(user)
} finally {
sql.close()
}
To execute groovy scripts in transition postfunction you need the ScriptRunner plugin.
Hope you will get an idea how to do what you want to do.
Original: https://www.cnblogs.com/freeliver54/p/15885392.html
Author: freeliver54
Title: Jira Connecting to databases Querying the Current JIRA Database
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/546184/
转载文章受原作者版权保护。转载请注明原作者出处!