You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
I'm trying to write a quick script that sets a custom variable called "Environment" which is a single pull-down selectable choice of the following values:
None
Dev
Test
QA
QA2
Prod
I have a Custom Listener setup as "VersionReleaseEvent and when I made my release, it does appear to be triggering my script which errors out immediately before and of my debug log statements even run.
Once a release happens, I want my custom variable "Environment" set to "Prod".
The code I've written is the following and it is erroring out on the event.issue line
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.issue.Issue
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
def mylog = Logger.getLogger("PushReleaseVersionToProd")
// Set log level
mylog.setLevel(Level.DEBUG)
def issue = event.issue as Issue
def EnvFieldName = 'Environment'
mylog.debug "EnvFieldName is $EnvFieldName"
def customFieldManager = ComponentAccessor.customFieldManager
def EnvField = customFieldManager.getCustomFieldObjects(issue).findByName(EnvFieldName)
assert EnvField : "Could not find custom field with name $EnvFieldName"
mylog.debug "EnvField is $EnvField at end of script"
EnvField = "Prod"
The error log is the following:
2021-07-29 14:18:32,284 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2021-07-29 14:18:32,286 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.project.VersionReleaseEvent, file: null
groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.jira.event.project.VersionReleaseEvent
at PushReleaseVersionToProd.run(PushReleaseVersionToProd.groovy:15)
I'd appreciate any help in trying to suss out what the issue may be.
Thanks,
Jeff
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.