I'm reading up on the Data Center 9.8 version on auto stop/start sprints: https://confluence.atlassian.com/jirasoftware/jira-software-9-8-x-release-notes-1224776099.html
And I was wondering if using ScriptRunner, how do I also auto export a saved filter or a saved Structure as a CSV file based on a sprint's Start and End dates?
For example, I have 6 sprints. Sprints 1-5 starts on a Wednesday at 4pm and closes 2 weeks later on a Wednesday at 12pm. And I export a saved filter before and after the sprint times (so around 11:59am and 4:01pm). This is all for metrics-building purposes that require more complex excel formulas I make later.
For sprint 6, it starts Wednesday 4pm, but closes 2 weeks later on Thursday 12pm, and I only do 1 export at 11:59am.
I had started out writing a custom script, but I'm wondering with the new 9.8 feature, I can remove the first blocks of code and try to find the sprint's assigned Start and End date.
Here's what I original have:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import java.util.TimeZone
import java.util.Calendar
// Define the timezone for the specified times (EST)
def estTimeZone = TimeZone.getTimeZone("America/New_York")
// Define the closing time for the old sprint in EST (12pm)
def estCloseHour = 12
def estCloseMinute = 0
// Define the starting time for the new sprint in EST (4pm)
def estStartHour = 16
def estStartMinute = 0
// Get the current date and time in EST timezone
def currentDate = Calendar.getInstance(estTimeZone)
// Check if it's time to close the old sprint
if (
currentDate.get(Calendar.HOUR_OF_DAY) >= estCloseHour &&
currentDate.get(Calendar.MINUTE) >= estCloseMinute &&
currentDate.get(Calendar.DAY_OF_WEEK == Calendar.WEDNESDAY &&
currentDate.get(Calendar.WEEK_OF_YEAR) %2 ==0) {
// Get the necessary Jira components
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def sprintManager = ComponentAccessor.getComponent(com.atlassian.greenhopper.service.sprint.SprintManager)
// Stop the current sprint
def currentSprint = sprintManager.getAllSprints().find { it.name == 'Your Current Sprint' }
if (currentSprint != null) {
sprintManager.closeSprint(currentUser, currentSprint.id)
}
}
// Check if it's time to start the new sprint
if (
currentDate.get(Calendar.HOUR_OF_DAY) >= estStartHour &&
currentDate.get(Calendar.MINUTE) >= estStartMinute) {
// Get the necessary Jira components
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def sprintManager = ComponentAccessor.getComponent(com.atlassian.greenhopper.service.sprint.SprintManager)
// Find the incomplete issues in the current sprint
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def jqlFilter = "Sprint = 'Your Current Sprint' AND status != 'Done'"
def currentSprintIssues = searchProvider.search(queryString: jqlFilter, user: currentUser, pagerFilter: new PagerFilter())
// Move incomplete issues to the next sprint
def nextSprintJqlFilter = "Sprint = 'Your Next Sprint'"
def nextSprint = searchProvider.search(queryString: nextSprintJqlFilter, user: currentUser, pagerFilter: new PagerFilter()).issues[0]
currentSprintIssues.getIssues().each { MutableIssue issue ->
issueManager.moveIssue(currentUser, issue, nextSprint)
}
// Start the new sprint
def newSprint = sprintManager.getAllSprints().find { it.name == 'Your Next Sprint' }
if (newSprint != null) {
sprintManager.updateSprint(currentUser, newSprint.id, newSprint.name, newSprint.startDate, newSprint.endDate, newSprint.goal)
}
}
// Export the saved filter as a CSV file
def filterManager = ComponentAccessor.getComponent(com.atlassian.jira.issue.search.SearchRequestManager)
def savedFilterName = "Your Saved Filter"
def savedFilter = filterManager.getSearchRequestByName(currentUser, savedFilterName)
def tempFile = File.createTempFile("exported-filter-", ".csv")
try {
def csvIssueWriter = ComponentAccessor.getComponent(com.atlassian.jira.issue.export.CsvIssueWriter)
csvIssueWriter.writeCsv(searchService, currentUser, savedFilter.getQuery(), tempFile)
} catch (Exception e) {
throw new RuntimeException("Failed to export filter as CSV", e)
}
I have yet to figure out the Wednesday/Thursday change for sprint 6 unique case, so is there a way using this and the auto sprint feature to just export my saved filters before and after my sprint date and time?