Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to auto export a CSV file with the auto stop/start sprint feature in Data Center 9.8?

Diana
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2023

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?

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 19, 2023

Hi @Diana Gorv

I have a doubt to clarify, i.e. what exactly are you trying to export to CSV? Is it the sprint's metadata?

I'm looking forward to your clarification.

Thank you and Kind regards,

Ram

Diana
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2023

hi @Ram Kumar Aravindakshan _Adaptavist_ 

Overall, my end goal is to find a way to auto export the issues in a saved filters before and after a sprint's end and start dates. I have a saved filter with desired columns needed to building metric reports, and because I have to export the issues in a saved filter at certain timestamps, I was hoping for a way to automate or create a reoccurring Job that will export the issues in the saved filter for me as a CSV file.

In summary what I do manually is: export issues from saved filter, close sprint, move incomplete issues to next sprint, export issues again, start sprint, export again.

All that, I hope to automate.

Suggest an answer

Log in or Sign up to answer