2015-11-02 101 views
0

請解釋我必須做什麼來關閉JIRA中的門票。我嘗試了很多變體,但沒有人幫助我。 有我的例子:通過JIRA中的groovy關閉門票

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 

它的工作正常。它會從篩選器中獲得所有問題,並顯示我或id或名稱,例如我不會。 需要在這個腳本中插入什麼,他們關閉了什麼?我的意思是改變狀態到已解決。

謝謝,你。

回答

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)");