I am trying to create jira ticket using groovy script (on Marid server from Opsgenie. However, I am facing issue when trying to setup component field.
import com.ifountain.opsgenie.client.http.OpsGenieHttpClient
import com.ifountain.opsgenie.client.util.ClientConfiguration
import com.ifountain.opsgenie.client.util.JsonUtils
import org.apache.http.HttpHeaders
LOG_PREFIX = "[${mappedAction}]:";
logger.info("${LOG_PREFIX} Will execute [${mappedAction}] for alertId ${params.alertId}");
CONF_PREFIX = "jira.";
HTTP_CLIENT = createHttpClient();
try {
String url = params.url
if (url == null || "".equals(url)) {
url = _conf("url", true)
}
String issueKey = params.key
String projectKey = params.projectKey
if (projectKey == null || "".equals(projectKey)) {
projectKey = _conf("projectKey", true)
}
String issueTypeName = params.issueTypeName
if (issueTypeName == null || "".equals(issueTypeName)) {
issueTypeName = _conf("issueType", true)
}
String username = params.username
String password = params.password
if (username == null || "".equals(username)) {
username = _conf("username", true)
}
if (password == null || "".equals(password)) {
password = _conf("password", true)
}
Map contentTypeHeader = [:]
contentTypeHeader[HttpHeaders.CONTENT_TYPE] = "application/json"
def authString = (username + ":" + password).getBytes().encodeBase64().toString()
contentTypeHeader[HttpHeaders.AUTHORIZATION] = "Basic ${authString}".toString()
contentTypeHeader[HttpHeaders.ACCEPT_LANGUAGE] = "application/json"
def contentParams = [:]
def fields = [:]
def project = [:]
def issuetype = [:]
def transitions = [:]
def resolution = [:]
def customfield = [:]
String resultUrl = url + "/rest/api/2/issue"
if (mappedAction == "addCommentToIssue") {
contentParams.put("body", params.body)
resultUrl += "/" + issueKey + "/comment"
} else if (mappedAction == "createIssue") {
issuetype.put("name", issueTypeName)
project.put("key", projectKey)
fields.put("project", project)
fields.put("issuetype", issuetype)
fields.put("summary", params.summary)
fields.put("description", params.description)
String toLabel = "ogAlias:" + params.alias
//fields.put("labels", Collections.singletonList(toLabel.replaceAll("\\s", "")))
customfield.put("value","Test")
fields.put("customfield_10714",customfield)
def components = [:]
components.put("name","Monitoring \\ Reports Async")
logger.debug("components ${components}")
def set = ["set":components]
contentParams.put("components", set)
contentParams.put("fields", fields)
The error I am facing is: ERROR: [createIssue]: Could not execute at Jira; response: 400 {"errorMessages":[],"errors":{"components":"Component/s is required."}}
Would appreciate if someone can assist how to set component field on creation