Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,417
Community Members
 
Community Events
175
Community Groups

Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null

Hello, I'm having some difficulty getting some code to work with a specific issue type of "Escalation" to the specific DBA webhook. I've been able to verify with our same slack webhook (removed for obvious reasons) is working and that other issue types are working. Here is the error message followed by the code.

 

ERROR

2023-01-19 09:13:50,660 WARN [runner.ScriptBindingsManager]: 
Atl Admin: false
Database Admin: true
Network Admin: false
Sys Admin: false
2023-01-19 09:13:50,660 INFO [runner.ScriptBindingsManager]: Issue Key: EDCO-248989 Issue Type is Escalation
2023-01-19 09:13:50,816 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2023-01-19 09:13:50,816 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
groovyx.net.http.HttpResponseException: status code: 400, reason phrase: Bad Request
at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.post(RESTClient.java:141)
at groovyx.net.http.RESTClient$post.call(Unknown Source)
at Script319.run(Script319.groovy:122)

 

SCRIPT

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig

log.setLevel(org.apache.log4j.Level.DEBUG)

def issue = event.issue as Issue
def typesToExclude = ["Change","Epic","Project Milestone","Project Deliverable (Sub-task)","Request Test"]

if(typesToExclude.contains(issue.issueType.name)) { log.info "Not a valid issue for notification"; return }

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()

CustomField cfaTeam = customFieldManager.getCustomFieldObject("customfield_14202") // Assigned Team
FieldConfig fcaTeam = cfaTeam.getRelevantConfig(issue)

Option sysa = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Systems Administration' }
Option dba = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Database Administration' }
Option na = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Network Administration' }
Option atl = optionsManager.getOptions(fcaTeam)?.find { it.getValue() == 'Atlassian Administration' }

Option teamOption = issue.getCustomFieldValue(cfaTeam) as Option

def isSysAdmin = sysa == teamOption
def isDba = dba == teamOption
def isNa = na == teamOption
def isAtl = atl == teamOption

def infTeamsList = [isAtl, isDba, isNa, isSysAdmin]


if(!infTeamsList.contains(true)) { log.warn "Not an Infrastructure Team"; return }
log.warn "\nAtl Admin: ${infTeamsList[0] as String}\nDatabase Admin: ${infTeamsList[1] as String}\nNetwork Admin: ${infTeamsList[2] as String}\nSys Admin: ${infTeamsList[3] as String}"

def webhookPath = ''
final webhookPathAtl = '/services/xxxx'
final webhookPathElOne = '/services/xxxxx'
final webhookPathElTwo = '/services/xxxxxx'
final webhookPathElThree = '/services/xxxxxxx'
final webhookPathElLeadership = '/services/xxxxxxxx'
final webhookPathNetworkAdmin = '/services/xxxxxxxxx'
final webhookPathDBA = 'services/xxxxxxxxxx'




if (isAtl) { webhookPath = webhookPathAtl }
else if (isDba) { webhookPath = webhookPathDBA }
else if (isNa) { webhookPath = webhookPathNetworkAdmin }
else if (isSysAdmin)
{
CustomField cfaEl = customFieldManager.getCustomFieldObject("customfield_19303") // Escalation Level
FieldConfig fcaEl = cfaEl.getRelevantConfig(issue)

Option one = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 1' }
Option two = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 2' }
Option three = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Level 3' }
Option leadership = optionsManager.getOptions(fcaEl)?.find { it.getValue() == 'Leadership' }

Option elOption = issue.getCustomFieldValue(cfaEl) as Option ?: one

def levelOne = one == elOption
def levelTwo = two == elOption
def levelThree = three == elOption
def levelLead = leadership == elOption

if(levelOne) {
log.debug "Sys Admin level 1 webhook path set"
webhookPath = webhookPathElOne
}
else if(levelTwo) {
log.debug "Sys Admin level 2 webhook path set"
webhookPath = webhookPathElTwo
}
else if(levelThree) {
log.debug "Sys Admin level 3 webhook path set"
webhookPath = webhookPathElThree
}
else if(levelLead) {
log.debug "Sys Admin Leadership webhook path set"
webhookPath = webhookPathElLeadership
}
else { log.error "Sys Admin detected, but no EL found. No notification sent."; return }

}
else {
log.error "No Alert Defined"
return
}

final webhookBase = 'https://hooks.slack.com'
def jiraBaseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)

//Issue detail augmentation
String org_summary = issue.summary
String summary = org_summary
String org_description = issue.description ?: ""
String description = org_description.replace("*Description copied from Parent:*","") ?: ""

String textBlock = "${issue.issueType.name}: <$jiraBaseUrl/browse/$issue.key|${summary}>"
log.info "Issue Key: ${issue.key} Issue Type is ${issue.issueType.name}"

def body = [
text: summary,
blocks: [
[
type: 'section',
text: [
type: 'mrkdwn',
text: textBlock
]
]
]
]

def response = new RESTClient(webhookBase).post(
path: webhookPath,
contentType: ContentType.HTML,
body: body,
requestContentType: ContentType.JSON
) as HttpResponseDecorator

assert response.status == 200: "Request failed with status $response.status. $response.entity.content.text"

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events