Forums

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

Script to set custom variable once a Jira release happens?

Jeff Hayes
Contributor
July 29, 2021

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

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 21, 2019

Epic links are a bit funny - they're not quite links, but logically, they are.

If you've got a script for "create issue X from Epic-123 and link X back to Epic-123", you're almost there.  But replace the "link X back to Y" with "update custom field 'epic link' with the 'epic name' on Epic-123"

Robert Anthony
May 27, 2019

Hi Nic,

I appreciate the answer but I'm not sure what the script would actually be. The default scripts do not provide something that will copy a value from one field on the original (Epic) issue to the newly cloned (Story) issue with a new custom field (Epic Link) to actually create that different "link". I'm relatively new to scripting and there doesn't seem to be any provided scripts that actually do this. 

TAGS
AUG Leaders

Atlassian Community Events