Forums

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

Update the releases automatically using Scriptrunner Schedule Jobs

Sreedevi Raman Pisharody June 6, 2023

I am trying to update the releases on a jira project using Scriptrunner Schedule jobs option :-

The code i used is as below 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager

// Specify the project key and release ID
def projectKey = "TJ" // Replace with the key of your Jira project
def releaseId = 1234 // Replace with the actual release ID

// Specify the new start and release dates
def newStartDate = new Date() // Replace with the desired start date
def newReleaseDate = new Date() + 7 // Replace with the desired release date

// Get the version manager
def versionManager = ComponentAccessor.getVersionManager()

// Find the release by project key and release ID
def release = versionManager.getVersion(projectKey, releaseId)
[Error message: [Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#getVersion(java.lang.String, int). Please check if the declared type is correct and if the method exists.]

// Update the start and release dates
release.setStartDate(newStartDate)
[Error message : [Static type checking] - Cannot find matching method java.lang.Object#setReleaseDate(java.util.Date). Please check if the declared type is correct and if the method exists.]
release.setReleaseDate(newReleaseDate)
[Error message: [Static type checking] - Cannot find matching method java.lang.Object#setStartDate(java.util.Date). Please check if the declared type is correct and if the method exists.]

// Save the changes
versionManager.updateVersion(release, false)
[Error message : [Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#updateVersion(java.lang.Object, boolean). Please check if the declared type is correct and if the method exists.]
I am getting errors at the bold lines.
Can you please help to fix this issue.

1 answer

0 votes
Najjar _Innovura_
Atlassian Partner
June 6, 2023 edited

you can use the editVersionStartReleaseDate method from the VersionManager class to update the start and release dates of a version. Here's an updated version of your script: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager

// Specify the project key and release ID
def projectKey = "TJ" // Replace with the key of your Jira project
def releaseId = 1234 // Replace with the actual release ID
def versionName = "APP V1.2.3"

// Specify the new start and release dates
def newStartDate = new Date() // Replace with the desired start date
def newReleaseDate = new Date() + 7 // Replace with the desired release date

// Get the version manager
def versionManager = ComponentAccessor.getComponent(VersionManager)

// Get the project by project key
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey)

// 2 ways to find the version:
// 1. Find the version using release or version id
def version = versionManager.getVersion( releaseId )

// or
// 2. Find the version by project ID and version name
// def version = versionManager.getVersionByName(project.id, versionName)

// Update the start and release dates if the version exists
if (version) {
// Update the start and release dates
versionManager.editVersionStartReleaseDate(version, newStartDate, newReleaseDate)
} else {
// Version not found
log.error("Version not found for project $projectKey and name $versionName.")
}


 

Sreedevi Raman Pisharody June 6, 2023

I tried the changed code as you suggested, however it gives error in the last line of editVersionStartReleaseDate as below

[Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#editVersionStartReleaseDate(java.lang.String, java.util.Date, java.util.Date). Please check if the declared type is correct and if the method exists.

I also tried the option of create version which also fails with error.

Najjar _Innovura_
Atlassian Partner
June 7, 2023

Code is updated, try now

Sreedevi Raman Pisharody June 8, 2023

I tried the changed code but it is still giving me error.

// Find the version by project ID and version name
def version = versionManager.getVersionByName(project.id, versionName)
Error : [Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#getVersionByName(java.lang.Long, java.lang.Object). Please check if the declared type is correct and if the method exists.
versionManager.editVersionStartReleaseDate(version, newStartDate, newReleaseDate)
Error : 
[Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#editVersionStartReleaseDate(java.lang.Object, java.util.Date, java.util.Date). Please check if the declared type is correct and if the method exists.
log.error("Version not found for project $projectKey and name $versionName.")
Error : [Static type checking] - The variable [versionName] is undeclared.
Najjar _Innovura_
Atlassian Partner
June 9, 2023

Code is updated once again. There are two ways to retrieve the version/release object

1. Find the version using release or version id

def version = versionManager.getVersion( releaseId ) 

 

2. Find the version by using project ID and version name 

def version = versionManager.getVersionByName(project.id, versionName)
Sreedevi Raman Pisharody June 28, 2023

Sorry for delayed response, we have could fix the issue. 

Thanks for your help

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.9
TAGS
AUG Leaders

Atlassian Community Events