I'm using groovy to try and automatically set an issue's FixVersion in a post function to one of 3 values, depending on where the issue is in our release pipeline.
For example, let's say I'm transitioning issue FOO-150, and I want to set its FixVersion to 1003 in the post function.
A tried to query the FixVersion of an existing issue (say BAR-42) whose FixVersion I had preset to 1003, but couldn't get it to work. Another way I thought of to try was to create the 3 FixVersions for the BAR project, but I don't see how to get the middle value - only the first() and last(). (Obviously, I'm a newbie at all of this ; )
Do either of those sound reasonable? or is there a better way?
I have JIRA Server v7.7.1 and ScriptRunner v5.4.12
Thanks!
Hello,
If there are 3 versions in the Fix Versions field. Then to take the second value and update the issue would be like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption;
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setFixVersions([issue.getFixVersions()[1]])
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
Thank you so much for your help -- I should have thought of trying the array annotation rather than just using the first() or last() functions...
Below is the code I'm using for the "Ready to Build" transition.
It works only if the issue I'm transitioning is in the ZFIN project. For issues in any other project, when I view the issue after the transition, I see the correct FixVersion, but when I edit the FixVersion field, FixVersion resets to "None". It doesn't seem that the value is being persistently stored in the database unless the issue is in the ZFIN project.
I'm wondering if this is happening because FixVersions are associated with specific projects, so when the code gets back "1098" as the FixVersion for the ZFIN project, regardless of the fact that I also have a FixVersion of "1098" for the INF project, JIRA doesn't recognize the string "1098" as a valid FixVersion for INF?
Any ideas for how to make this work?
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Site variable is field #10103
def cSiteField = customFieldManager.getCustomFieldObject("customfield_10103")
def cSite = (String) issue.getCustomFieldValue(cSiteField)
def cStatus = (String) issue.getStatus()?.name
def groupManager = ComponentAccessor.getGroupManager()
// used to get the FixVersion value from the specific ZFIN-42 issue
def issueManager = ComponentAccessor.getIssueManager()
def targetIssue = issueManager.getIssueByCurrentKey("ZFIN-42")
if (cSite == "TRUNK")
{
groupManager.getUsersInGroup("CC-ReleaseOnTRUNK").each {
issue.setAssignee(it)
}
issue.setFixVersions([targetIssue.getFixVersions()[2]])
}
else if (cSite == "TEST")
{
groupManager.getUsersInGroup("CC-ReleaseOnTEST").each {
issue.setAssignee(it)
}
issue.setFixVersions([targetIssue.getFixVersions()[1]])
}
else if (cSite == "PROD")
{
groupManager.getUsersInGroup("CC-ReleaseOnPROD").each {
issue.setAssignee(it)
}
issue.setFixVersions([targetIssue.getFixVersions()[0]])
}
import com.atlassian.jira.event.type.EventDispatchOption;
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@zfinannee
did you ever made your script work through different projects?
I have the exact same problem, want to copy the fixversion from an issue in one project to an issue in another project.
When editing the copied fixversion the field got blank. I have also problems with the view releases for the project where issues with copied fix versions are not listed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@zfinannee I found a solution on my own.
I added a loop were the fixversion is cut into the different versions, saves as a string and after that i searched for this string in the projekt versions of the linked issue.
The problem was that we have the same release in different projects and my script copies version from the project A to project B with the false ID.
This is my new code:
// Check if fixVersion is updated
if (LastChangeDate != null){
LastChangeDateFormat = LastChangeDate.format("yyyy-MM-dd hh:mm:ss")
}
if (LastChangeDateFormat >= currentDate) {
log.debug("${issueKey} fixVersions changed ${LastChangeDate}")
def fixVersions = issue.getFixVersions()
log.debug("FixVersion DEV-Ticket lautet ${fixVersions}")
// Updating FixVersions in Customer Issue
if (issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
for (IssueLink link in issueLinkManager.getOutwardLinks(issue.getId()).findAll {it.issueLinkType.name == 'Customer Project'}) {
def destIssueCust = link.getDestinationObject()
def projectCust = destIssueCust.getProjectObject().getId();
def versionsCust = []
log.debug("Projekt = ${projectCust}")
for (version in fixVersions) {
String strVersion = version
versionsProject = versionManager.getVersion(projectCust, strVersion)
versionsCust.add(versionsProject)
}
destIssueCust.setFixVersions(versionsCust)
log.debug("FixVersion CUST-Ticket lautet ${destIssueCust.getFixVersions()}")
ComponentAccessor.getIssueManager().updateIssue(CurrentUser, destIssueCust, com.atlassian.jira.event.type.EventDispatchOption.ISSUE_UPDATED, false);
log.debug("${issueKey} fixVersions changed in customer issue ${destIssueCust}")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.