在JIRA通过groovy关闭门票

时间:2015-11-02 16:10:44

标签: linux apache jira load-balancing

请解释我必须做些什么来关闭JIRA的门票。我尝试了很多变种,但没有人帮助我。 有我的例子:

import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters
import java.util.Date
import java.util.Calendar
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import java.util.List

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ctx = new JiraServiceContextImpl(user)
def searchRequestService = ComponentManager.getInstance().getSearchRequestService()
def searchProvider = ComponentManager.getInstance().getSearchProvider()
def sr = searchRequestService.getFilter(ctx, 17540)
def searchResult = searchProvider.search(sr?.getQuery(), user, PagerFilter.getUnlimitedFilter())
def issueManager = ComponentManager.getInstance().getIssueManager()
def issues = searchResult.getIssues().collect {issueManager.getIssueObject(it.id)}

for ( issue in issues ){
    def id=issue.getId()
}
return issues

它正常工作。它从过滤器中获取所有问题,并显示我或身份或姓名,就像我不会。 什么需要插入这个脚本,它们关闭它?我的意思是将状态更改为已解决。

谢谢,你。

1 个答案:

答案 0 :(得分:0)

您需要在问题状态和关闭状态之间进行转换,然后针对每个问题执行此转换。您可以在工作流程菜单中找出转换的ID(只需将工作流程显示为文本。

在此示例中,您可以看到如何执行问题列表的转换。

int actionId = 701; // transition id from Done to Closed    
for (Issue issue in issues) {
            log.info("Closing ${issue.key}: ${issue.summary}");
            IssueInputParameters params = cm.getIssueService().newIssueInputParameters();
            params.setRetainExistingValuesWhenParameterNotProvided(true);
            if (comment) params.setComment(comment);
            log.debug("Action parameters: ${params.actionParameters}");

            TransitionValidationResult validation = cm.getIssueService().validateTransition(user,issue.getId(),actionId,params);
            log.debug("Addition inputs: ${validation.additionInputs}");
            if (validation.isValid()) {
                IssueResult result = cm.getIssueService().transition(user,validation);
                if (result.isValid()) log.debug("${result.errorCollection}");
                else log.error("${result.errorCollection}");
            } else {
                result = null;
                log.error("Errors: ${validation.errorCollection.errors}");
            }
        }

        log.info("Done closing ${issues.size()} issue(s)");