I am trying to schedule a kanban board to be automatically released on a schedule (5PM Monday-Friday). The board is mostly automated, we use it to monitor our dataload process. It has ~100 tickets created per day, so the resolved column stacks up fast and needs to be released regularly to keep it readable. Until now, we had just been doing it before we leave at night, but I'd rather have it automated. I wrote 2 scripts that are running in scriptrunner escalation services right now- one to create/assign a version to the tickets, and another that runs 5 mins later to release the version (I'll put the scripts at the bottom of this post). The scripts work as intended, but I think the actual versions in the projects aren't refreshing their issues properly. When I come in in the morning, the board has not released, but when I go to the project>Releases, it says there are only two issues for the version (When searching for the versions with a jql query, it pulls up 40+). If I click on the version, it reloads the issues and the issues disappear from the board. How can I integrate the process of refreshing the list of issues in the version into my scripts?
Script to create/assign the version:
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import java.util.Date
import java.text.SimpleDateFormat
import java.util.Calendar
//Query: (project = "Data Loads" or project = "Data Loads Direct") and fixVersion not in releasedVersions() and status = closed order by created DESC
def versionManager = ComponentAccessor.getVersionManager()
def project = new ArrayList<Project>()
project.add(issue.getProjectObject())
Date now = new Date()
String pattern = "MM/dd/yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String name = simpleDateFormat.format(now)
def allVersions = versionManager.getAllVersionsForProjects(project, false)
def allNames = new ArrayList<String>()
for (v in allVersions)
{
allNames.add(v.name)
}
def versionExists = allNames.contains(name)
def currentVersion
if(versionExists)
{
currentVersion = allVersions[allNames.indexOf(name)]
}
else
{
Calendar calendar = Calendar.getInstance();
// Add 5 minutes to the calendar time
calendar.add(Calendar.MINUTE, 5);
def future = calendar.getTime()
currentVersion = versionManager.createVersion(name,now -1,future,"Autogenerated version for dataload tickets",issue.projectObject.id,null)
//currentVersion = versionManager.releaseVersion(currentVersion, true)
}
def versions = new ArrayList<Version>()
versions.add(currentVersion)
issue.setFixVersions(versions)
def user = ComponentAccessor.getUserManager().getUserByKey("ETLService")
ComponentAccessor.getIssueManager().updateIssue(user, issue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH,false)
Script to release the version:
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import java.util.Date
import java.text.SimpleDateFormat
import java.util.Calendar
import com.atlassian.jira.bc.project.version.VersionService
//Query: (project = "Data Loads" or project = "Data Loads Direct") and fixVersion not in releasedVersions() and status = closed order by created DESC
//Cron: 0 0 17 ? * MON-FRI
def versionManager = ComponentAccessor.getVersionManager()
def project = new ArrayList<Project>()
project.add(issue.getProjectObject())
Date now = new Date()
String pattern = "MM/dd/yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String name = simpleDateFormat.format(now)
def allVersions = versionManager.getAllVersionsForProjects(project, false)
def allNames = new ArrayList<String>()
for (v in allVersions)
{
allNames.add(v.name)
}
def versionExists = allNames.contains(name)
def currentVersion
if(versionExists)
{
currentVersion = allVersions[allNames.indexOf(name)]
}
def versionService = ComponentAccessor.getComponent(VersionService)
def user = ComponentAccessor.getUserManager().getUserByKey("ETLService")
def result = versionService.validateReleaseVersion(user, currentVersion, now)
if (result.isValid())
{
versionService.releaseVersion(result)
}
else
{
log.error "Could not release version '${currentVersion.name}' due to the following errors: $result.errorCollection.errors"
}
Is there a way to do this with a VersionService or something?
Thanks in advance!