According to documentation there is interface called BoardManager which includes method called getBoardsForProject(long projectId). This sounds like exactly what I need but for some reason, no matter the project, it always returns null.
Here's my ScriptRunner code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.board.Board
import com.atlassian.jira.board.BoardManager
def boardManager = ComponentAccessor.getComponent(BoardManager);
def b = boardManager.getBoardsForProject(12401);
return b;
When using the same project id in REST API call /rest/agile/1.0/board?projectKeyOrId=12401, I'm getting the Boards I'm expecting. I know, it is possible to use REST API calls in ScriptRunner as well, but this is something I don't want to do.
Any ideas, how to modify my script to get the needed data?
//I have tried the following and all return nothing. The Rapidview service is not even returning an instnace of the service :(
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.ServiceOutcome
import com.atlassian.jira.board.BoardManager
import com.atlassian.jira.board.BoardService
import com.atlassian.jira.board.Board
import com.atlassian.jira.board.store.BoardStore
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintService
import com.atlassian.jira.user.ApplicationUser
log.setLevel(Level.DEBUG)
def boardManager = ComponentAccessor.getComponent(BoardManager)
def boardService = ComponentAccessor.getComponent(BoardService)
def boardStore = ComponentAccessor.getComponent(BoardStore)
def rapidViewService = ComponentAccessor.getComponent(RapidViewService)
def sprintService = ComponentAccessor.getComponent(SprintService)
def projectManager = ComponentAccessor.projectManager
ApplicationUser me = ComponentAccessor.jiraAuthenticationContext.loggedInUser
String result = "<span>Hi</span>"
def out = rapidViewService.getRapidViews(me)
out.get().each {
result += "<br />$it"
}
projectManager.projects.each { project ->
List<Board> projectBoards = boardManager.getBoardsForProject(project.id)
result += "<br />$project -> $projectBoards"
projectBoards.each { board ->
result += "<br/>$project -> $board"
}
projectBoards = boardStore.getBoardsForProject(project.id)
result += "<br />$project -> $projectBoards"
projectBoards.each{ board ->
result += "<br />$project -> $board"
}
ServiceOutcome<List<Board>> outcome = boardService.getBoardsForProject(me, project.id)
projectBoards = outcome.get()
result += "<br />$project -> $projectBoards"
projectBoards.each { board ->
result += "<br />$project -> $board"
}
}
return result
I have found two ways to get to these services and managers.
1)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While this does return information about boards, it doesn't return a list of boards associated with each project.
All three getBoardsForProject implementations still return null.
Code I tried:
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.ServiceOutcome
import com.atlassian.jira.board.BoardManager
import com.atlassian.jira.board.BoardService
import com.atlassian.jira.board.Board
import com.atlassian.jira.board.store.BoardStore
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintService
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
log.setLevel(Level.DEBUG)
def boardManager = ComponentAccessor.getComponent(BoardManager)
def boardService = ComponentAccessor.getComponent(BoardService)
def boardStore = ComponentAccessor.getComponent(BoardStore)
def rapidViewService = ComponentAccessor.getOSGiComponentInstanceOfType(RapidViewService)
def sprintService = ComponentAccessor.getComponent(SprintService)
def projectManager = ComponentAccessor.projectManager
ApplicationUser me = ComponentAccessor.jiraAuthenticationContext.loggedInUser
String result = "<span>Hi</span>"
def out = rapidViewService.getRapidViews(me)
out.get().each {
result += "<br />$it"
}
projectManager.projects.each { project ->
List<Board> projectBoards = boardManager.getBoardsForProject(project.id)
result += "<br />$project -> $projectBoards"
projectBoards.each { board ->
result += "<br/>$project -> $board"
}
projectBoards = boardStore.getBoardsForProject(project.id)
result += "<br />$project -> $projectBoards"
projectBoards.each{ board ->
result += "<br />$project -> $board"
}
ServiceOutcome<List<Board>> outcome = boardService.getBoardsForProject(me, project.id)
projectBoards = outcome.get()
result += "<br />$project -> $projectBoards"
projectBoards.each { board ->
result += "<br />$project -> $board"
}
}
return result
Result:
Project: TSTKB -> []
Project: TSTKB -> []
Project: TSTKB -> []
Project: ATDEV -> []
Project: ATDEV -> []
Project: ATDEV -> []
Project: AV -> []
Project: AV -> []
Project: AV -> []
Project: ATL -> []
Project: ATL -> []
Project: ATL -> []
etc
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It just turns out this is part of Jira Agile so this is the place to do things regarding sprints, ranking, boards etc.
com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.rapid.view.RapidViewServiceimport com.atlassian.greenhopper.service.sprint.SprintServiceimport com.atlassian.greenhopper.service.sprint.SprintManagerimport com.atlassian.greenhopper.service.sprint.SprintIssueServiceimport com.atlassian.greenhopper.service.sprint.SprintQueryServiceimport com.atlassian.greenhopper.service.sprint.SprintHistoryServiceimport com.atlassian.greenhopper.service.sprint.Sprintimport com.atlassian.greenhopper.service.sprint.Sprint.SprintBuilderimport com.onresolve.scriptrunner.runner.customisers.JiraAgileBeanimport com.onresolve.scriptrunner.runner.customisers.WithPlugin@WithPlugin( "com.pyxis.greenhopper.jira" )@JiraAgileBean RapidViewService rapidViewService@JiraAgileBean SprintIssueService sprintIssueService@JiraAgileBean SprintQueryService sprintQueryService@JiraAgileBean SprintHistoryService sprintHistoryService@JiraAgileBean SprintManager sprintManager@JiraAgileBean SprintService sprintService
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After bumbling about a bit I have found what I think you are looking for @Jürgen Talik
import org.apache.log4j.Levelimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.project.ProjectManagerimport com.atlassian.jira.project.Projectimport com.atlassian.greenhopper.service.ServiceOutcomeimport com.atlassian.greenhopper.service.rapid.ProjectRapidViewServiceimport com.atlassian.greenhopper.model.rapid.RapidViewimport com.onresolve.scriptrunner.runner.customisers.JiraAgileBeanimport com.onresolve.scriptrunner.runner.customisers.WithPluginlog.setLevel(Level.INFO)@WithPlugin('com.pyxis.greenhopper.jira')@JiraAgileBean ProjectRapidViewService projectRapidViewServiceProjectManager projectManager = ComponentAccessor.projectManagerApplicationUser me = ComponentAccessor.jiraAuthenticationContext.loggedInUser// @FIXME Use markup builder insteadString result = ''String[] keys = ['TSTKB', 'ATDEV', 'AV', 'ATL']keys.each { pKey ->Project project = projectManager.getProjectByCurrentKey(pKey)log.info("Searching for rapid view bords that belong to ${project.name}")result += "<h3>${project.key}</h3>"projectRapidViewService.findRapidViewsByProject(me, project).each { outcome ->List<RapidView> boards = ((ServiceOutcome<List<RapidView>>)outcome).valueboards.each { rv ->result += "${rv.name}<br/>"}}result += "<hr />"}return result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fantastic, thank you @Graham Twine! Indeed, ProjectRapidViewService was the missing piece of the puzzle!
Here is my MVP code for anyone interested:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.greenhopper.service.rapid.ProjectRapidViewService
import com.atlassian.greenhopper.model.rapid.RapidView
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import groovy.json.JsonOutput
@JiraAgileBean ProjectRapidViewService projectRapidViewService
ProjectManager projectManager = ComponentAccessor.projectManager;
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Project project = projectManager.getProjectObj(12401);
log.warn("List of boards for project: ${project.getKey()}");
List<RapidView> boards = projectRapidViewService.findRapidViewsByProject(currentUser, project).value;
log.warn(JsonOutput.toJson(boards));
Edit: Optimized the code a bit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jürgen Talikcan you mark this as accepted if it is the correct response
Including the filter query for each board and format into a table.
I really should be using the MarkupBuilder instad of formatting HTML in strings :(
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.greenhopper.service.ServiceOutcome
import com.atlassian.greenhopper.service.rapid.ProjectRapidViewService
import com.atlassian.greenhopper.model.rapid.RapidView
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
log.setLevel(Level.INFO)
@WithPlugin('com.pyxis.greenhopper.jira')
@JiraAgileBean ProjectRapidViewService projectRapidViewService
ProjectManager projectManager = ComponentAccessor.projectManager
SearchRequestManager srManager = ComponentAccessor.getComponent(SearchRequestManager)
ApplicationUser me = ComponentAccessor.jiraAuthenticationContext.loggedInUser
String[] keys = ['TSTKB', 'ATDEV', 'AV', 'ATL']
// @FIXME Use markup builder instead
String result = ''
keys.each { pKey ->
Project project = projectManager.getProjectByCurrentKey(pKey)
String projectData = "<h3>${project.key} ${project.name}</h3>"
projectData +=
"""<table class="aui aui-table-sortable">
<thead>
<tr>
<th>Board Id</th>
<th>Board Name</th>
<th>Filter Query</th>
</tr>
</thead>
<tbody>
"""
projectRapidViewService.findRapidViewsByProject(me, project).each { outcome ->
List<RapidView> boards = ((ServiceOutcome<List<RapidView>>)outcome).value
boards.each { rv ->
SearchRequest sr = srManager.getSearchRequestById(rv.savedFilterId)
projectData += "<tr><td>${rv.id}</td><td>${rv.name}</td><td>${sr.query}</td></tr>"
}
}
projectData += "</tbody></table>"
result += projectData
}
return result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Graham Twine Amazing script!
We are migrating a JIRA Server to Cloud and many business project were failing because they were used in kanban board (see limitation below)
We adapted the script to fetch all projects of business type:
// add import for
import java.util.stream.Collectors
// replace keys variable to populate with all projects with type Business
// String[] keys = ['TSTKB', 'ATDEV', 'AV', 'ATL']
String[] keys = projectManager.getProjectObjects().stream().filter(it -> it.getProjectTypeKey().getKey().equals("business")).map(it->it.getKey()).collect(Collectors.toList()).toArray()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One could use some criteria such as project category or type get a list of projects instead of just adding a list.
In Scriptrunner ...
projectManager.projectObjects.findAll { project ->
project.projectTypeKey.key == "business"
}.each {
// do something with the filtered projects such as above
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there any chance of getting a Jira Cloud version of this SR code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.