ScriptRunner for Jira
You can use Golive with ScriptRunner for Jira, here are some inspirational use cases.

Groovy Scripts Examples

You can search and update Golive data using Golive Java components in custom groovy scripts. These scripts can then be used by workflow validators, postfunctions, listeners or any other ScriptRunner components.
In order to remove repetitive "boiler plate" code, we strongly advise you to structure your groovy code into small re-usable classes.

Example: update attributes of an environment

Script example to get an Environment and update its attributes:
Script Example
EnvironmentHelper
EnvironmentServicesAccessor
1
package com.apwide.golive.example
2
3
import com.apwide.env.environment.Environment
4
import com.apwide.golive.helper.EnvironmentHelper
5
6
EnvironmentHelper helper = new EnvironmentHelper()
7
8
Environment environment = helper.getEnvironment("eCommerce", "Staging")
9
10
String owner = "Fred"
11
12
String team = "Red Team"
13
String teamUrl = "https://red-team.example.com"
14
15
environment = helper.setAttributes(environment, ["Team": """<a href="${teamUrl}">${team}</a>""", "Owner": owner])
16
17
return """
18
Updated environment : ${environment},
19
Team=${helper.getAttributeValue(environment, "Team")},
20
Owner=${helper.getAttributeValue(environment, "Owner")}
21
"""
22
23
24
Copied!
This script depends on com.apwide.golive.helper.EnvironmentHelper and com.apwide.golive.accessor.EnvironmentServicesAccessor groovy classes (you can copy code from tabs above). Files must be structured that way in your script root:
1
package com.apwide.golive.helper
2
3
import com.apwide.env.attribute.Attribute
4
import com.apwide.env.attribute.AttributeTypeManager
5
import com.apwide.env.attribute.value.AttributeValue
6
import com.apwide.env.common.BaseResult
7
import com.apwide.env.common.ErrorCollectionHelper
8
import com.apwide.env.environment.Environment
9
import com.apwide.env.environment.admin.EnvironmentInputParameters
10
import com.apwide.env.environment.admin.EnvironmentManager
11
import com.apwide.env.environment.search.EnvironmentSearcher
12
import com.apwide.env.service.EnvironmentServices
13
14
import com.apwide.golive.accessor.EnvironmentServicesAccessor
15
16
import groovy.util.logging.Log4j
17
18
@Log4j
19
class EnvironmentHelper {
20
21
EnvironmentServices environmentServices = EnvironmentServicesAccessor.get()
22
EnvironmentSearcher environmentSearcher = environmentServices.getEnvSearcher()
23
EnvironmentManager environmentManager = environmentServices.getEnvMgr()
24
25
Environment getEnvironment(String applicationName, String categoryName) {
26
BaseResult<Environment> result = environmentSearcher.getByUnique(applicationName, categoryName)
27
if (result.hasAnyErrors()) {
28
log.error(ErrorCollectionHelper.displayErrors(result.getErrorCollection()))
29
return null
30
}
31
return result.getEntity()
32
}
33
34
Environment setAttributes(Environment environment, Map<String, String> attributes) {
35
List<AttributeValue> attributeValues = attributes.entrySet().stream().map({ entry ->
36
Attribute attribute = Attribute.fromName(entry.key)
37
return new AttributeValue.AttributeValueBuilder().attribute(attribute).value(entry.value).build()
38
}).toArray()
39
40
EnvironmentInputParameters params = new EnvironmentInputParameters()
41
params.setAttributes(attributeValues)
42
43
BaseResult<Environment> result = environmentManager.update(environment.getID(), params)
44
if (result.hasAnyErrors()) {
45
log.error(ErrorCollectionHelper.displayErrors(result.getErrorCollection()))
46
return null
47
}
48
return result.getEntity()
49
}
50
51
String getAttributeValue(Environment environment, String attributeName){
52
if (!environment.getAttributes())
53
return null
54
AttributeValue attributeValue = environment.getAttributes().find({AttributeValue attributeValue -> attributeValue.attribute.name == attributeName})
55
return attributeValue?.value
56
}
57
58
59
}
60
Copied!
1
package com.apwide.golive.accessor
2
3
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
4
@WithPlugin("com.holydev.env.plugin.jira-holydev-env-plugin")
5
6
import com.atlassian.jira.component.ComponentAccessor
7
import com.apwide.env.service.GoliveEnvironmentServices
8
9
class EnvironmentServicesAccessor {
10
static GoliveEnvironmentServices get(){
11
final Class serviceClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.apwide.env.service.GoliveEnvironmentServices")
12
return ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass)
13
}
14
}
15
Copied!

Auto-completion in your favorite IDE

In order to import Golive classes in your favorite IDE and to enable auto-completion:
    unrar or unzip the golive .obr file
    add the extracted apwide-golive-*.jar file to your classpath or add it to Maven dependencies of your project

Behaviours - Booking Conflicts

Using ScriptRunner Behaviours, we have added a banner showing the Environment Booking Conflicts:
Environment Booking Conflicts displayed using ScriptRunner Behaviours
For more information about this use case, refer to the Booking System page.

Behaviours - Version Autofill

Using ScriptRunner Behaviours, it is easy to prefill the "Affects Version/s" based on the selected Environments:
For more information about this use case, refer to the Version Autofill Page.

Behaviours - Fields update

In this example, we update the issue Summary with the list of Environments selected in an Environment Custom Field. As the custom field returns a list of Environment IDs, we use the Golive CustomFieldType to get the Environment names:
Environments added in the field "Environment(s) to book" are added in the Summary
ScriptRunner Behaviour Field setup
1
import com.atlassian.jira.issue.customfields.CustomFieldType
2
3
// Get the list of Environments' IDs from the Environment CF
4
def envField = getFieldById("customfield_10508")
5
List<String> envIds = envField ? (List) envField.getValue() : null
6
7
// Get the list of Environments' names from the list of IDs
8
CustomFieldType environmentCustomFieldType = customFieldManager.getCustomFieldType('com.holydev.env.plugin.jira-holydev-env-plugin:holydev_environment_customfield')
9
List envNames = envIds.collect { envId ->
10
environmentCustomFieldType.getSingularObjectFromString(envId).getName()
11
}
12
13
// Update the Summary field with the list of Environments
14
getFieldByName("Summary").setFormValue("Booking " + envNames.join(", "))
Copied!

Script Listeners

In this example, we automatically select the target Environment in our Change Requests (Jira issues), depending on the type of change defined in the "Promotion Path" field (Production Fix, Change Request, Enhancement).
For that, we have created a ScriptRunner Listener:
ScriptRunner Listener
1
import com.atlassian.jira.component.ComponentAccessor
2
import com.atlassian.jira.issue.ModifiedValue
3
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
4
5
def customFieldManager = ComponentAccessor.customFieldManager
6
def issue = event.issue
7
8
final environmentCustomFieldName = 'Environment(s)'
9
def environmentCustomField = customFieldManager.getCustomFieldObjects(issue).findByName(environmentCustomFieldName)
10
assert environmentCustomField : "Could not find custom field with name $environmentCustomFieldName"
11
12
final triggerCustomFieldName = 'Promotion Path'
13
def triggerCustomField = customFieldManager.getCustomFieldObjects(issue).findByName(triggerCustomFieldName)
14
assert triggerCustomField : "Could not find custom field with name $triggerCustomFieldName"
15
16
if (issue.getCustomFieldValue(triggerCustomField).toString() == "Enhancement") {
17
def customFieldType = environmentCustomField.getCustomFieldType()
18
def environment1 = customFieldType.getSingularObjectFromString("58") // eCommerce DEV1
19
def environment2 = customFieldType.getSingularObjectFromString("467") // eCommerce Test
20
def environmentList = [environment1, environment2]
21
environmentCustomField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(environmentCustomField), environmentList), new DefaultIssueChangeHolder())
22
}
Copied!

Questions?

If you need help with your Golive-ScriptRunner integration, feel free to contact us.
Last modified 3mo ago