For VersionReleaseEvent the event won't have an issue variable.
So event.issue is not an option
Which issue do you expect to be updated?
Think in terms of the UI. If you release a version in the project release page, how would you select which issue to update?
Peter,
Thanks for the excellent questions. I'm chalking it up to not enough coffee this morning. :)
What I'm really wanting to do is set every single issue's "Environment" to "Prod" in a given release. So if I have 6 issues in a release, I want all of their Environment custom variable values to be "Prod".
Does that help clarify?
Thanks,
Jeff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For reference, what I HAVE been doing is using a JQuery to show me every issue in a specific "fix version" and then using the bulk update tool to set that custom variable called "Environment" to "Prod".
Jeff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
think you mean JQL (Jira query language) not JQuery (javascript module).
I think your scriptrunner custom listener can take care of the JQL and Bulk update ... something along the lines of the following should get you close:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.search.SearchService
def mylog = Logger.getLogger("PushReleaseVersionToProd")
// Set log level
mylog.setLevel(Level.DEBUG)
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def searchService = ComponentAccessor.getComponent(SearchService)
def indexingService = ComponentAccessor.getComponent(IssueIndexingService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//this closure will be caller later for each issue
def updateIssueAndReIndex = {MutableIssue issue->
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false) //set to true to send notifications
//update the JIRA index
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
indexingService.reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)
}
def version = event.version
def EnvFieldName = 'Environment'
mylog.debug "EnvFieldName is $EnvFieldName"
def jql = """fixVersion = $version.id and "$EnvFieldName" != Prod"""
def parseResult = searchService.parseQuery(currentUser, jql)
searchService.search(currentUser, parseResult.query, PagerFilter.unlimitedFilter ).results.each{indexIssue ->
def issue = issueManager.getIssueObject(indexIssue.id)
def EnvField = customFieldManager.getCustomFieldObjects(issue).findByName(EnvFieldName)
mylog.debug "EnvField is $EnvField"
assert EnvField : "Could not find custom field with name $EnvFieldName for $issue.key"
mylog.debug "EnvField current Value for $issue is ${issue.getCustomFieldValue(EnvField)} setting it to 'Prod'"
issue.setCustomFieldValue(EnvField, 'Prod') // <-- this will only work if EnvField is a text field. If it's a select, you'll need to find the OptionId that correspond to the label "Prod"
//now you must save and re-index the issue
updateIssueAndReIndex(issue )
}
mylog.debug "At end of script"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! And yes, my custom field is an actual 6 (single) choice select, so I'll need to figure out how to change your syntax to use that specific choice field. I will let try to work on this and get back to you if I run into further issues.
Jeff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.