我正在尝试使用groovy脚本创建jira票证(在Opsgenie的Marid服务器上)。 但是,我在尝试设置组件字段时遇到问题。
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)
我面临的错误是: 错误:[createIssue]:无法在Jira执行;响应:400 {" errorMessages":[],"错误":{"组件":"组件是必需的。"} }
如果有人可以协助如何在创作中设置组件字段
,我们将不胜感激答案 0 :(得分:2)
根据JIRA的REST API documentation,您应该将组件列表放入字段映射中。此外,JIRA REST API仅根据doc支持有效内容中的组件ID。您应首先检索组件ID,然后您可以像这样使用它
def components = [
["id": "my_component_id_1"]
["id": "my_component_id_2"]
]
fields.put("components", components)
如果您还有其他问题,请与我们联系。