jira创建条目rest实用脚本

最近在搞crash崩溃分析,直接把解析到的信息录入jira系统进行跟踪;

经历了多次碰壁后终于调通,现记录一下

实用json请求脚本如下:

复制代码
{
                "fields":{
                        "project":{
                                "id":"10945"
                        },
                        "issuetype":{
                                "id":"10103"
                        },
                        "summary":"%s",
                        "description":"%s",
                        "components":[
                                {
                                        "id":"16001"
                                }
                        ],
                        "versions":[
                                {
                                        "id":"16600"
                                }
                        ],
                        "customfield_12108":{
                                "id":"12972"
                        },
                        "customfield_12109":{
                                "id":"12974"
                        },
                        "priority":{
                                "id":"10102"
                        },
                        "security":{
                                "id":"10600"
                        },
                        "assignee":{
                                "name":"%s"
                        }
                }
        }

两个注意点:

1、代码里%s 是我这边他要替换的字符串;

2、上面的id值需要自己抓包来确定,每个project各id值是不一样的,

一般抓包工具是Charles和Fiddler;

jira建单官方示例如下:

The Jira Cloud platform REST API

复制代码
// The payload definition using the Jackson library
JsonNodeFactory jnf = JsonNodeFactory.instance;
ObjectNode payload = jnf.objectNode();
{
  ObjectNode fields = payload.putObject("fields");
  {
    ObjectNode assignee = fields.putObject("assignee");
    {
      assignee.put("id", "5b109f2e9729b51b54dc274d");
    }
    ArrayNode components = fields.putArray("components");
    ObjectNode components0 = components.addObject();
    {
      components0.put("id", "10000");
    }
    fields.put("customfield_10000", "09/Jun/19");
    fields.put("customfield_20000", "06/Jul/19 3:25 PM");
    ArrayNode customfield_30000 = fields.putArray("customfield_30000");
    customfield_30000.add("10000");
    customfield_30000.add("10002");
    fields.put("customfield_40000", "Occurs on all orders");
    fields.put("customfield_50000", "Could impact day-to-day work.");
    fields.put("customfield_60000", "jira-software-users");
    ArrayNode customfield_70000 = fields.putArray("customfield_70000");
    customfield_70000.add("jira-administrators");
    customfield_70000.add("jira-software-users");
    ObjectNode customfield_80000 = fields.putObject("customfield_80000");
    {
      customfield_80000.put("value", "red");
    }
    fields.put("description", "Order entry fails when selecting supplier.");
    fields.put("duedate", "2019-03-11");
    fields.put("environment", "UAT");
    ArrayNode fixVersions = fields.putArray("fixVersions");
    ObjectNode fixVersions0 = fixVersions.addObject();
    {
      fixVersions0.put("id", "10001");
    }
    ObjectNode issuetype = fields.putObject("issuetype");
    {
      issuetype.put("id", "10000");
    }
    ArrayNode labels = fields.putArray("labels");
    labels.add("bugfix");
    labels.add("blitz_test");
    ObjectNode parent = fields.putObject("parent");
    {
      parent.put("key", "PROJ-123");
    }
    ObjectNode priority = fields.putObject("priority");
    {
      priority.put("id", "20000");
    }
    ObjectNode project = fields.putObject("project");
    {
      project.put("id", "10000");
    }
    ObjectNode reporter = fields.putObject("reporter");
    {
      reporter.put("id", "5b10a2844c20165700ede21g");
    }
    ObjectNode security = fields.putObject("security");
    {
      security.put("id", "10000");
    }
    fields.put("summary", "Main order flow broken");
    ObjectNode timetracking = fields.putObject("timetracking");
    {
      timetracking.put("originalEstimate", "10");
      timetracking.put("remainingEstimate", "5");
    }
    ArrayNode versions = fields.putArray("versions");
    ObjectNode versions0 = versions.addObject();
    {
      versions0.put("id", "10000");
    }
  }
  ObjectNode update = payload.putObject("update");
  {
    ArrayNode worklog = update.putArray("worklog");
    ObjectNode worklog0 = worklog.addObject();
    {
      ObjectNode add = worklog0.putObject("add");
      {
        add.put("started", "2019-07-05T11:05:00.000+0000");
        add.put("timeSpent", "60m");
      }
    }
  }
}

// Connect Jackson ObjectMapper to Unirest
Unirest.setObjectMapper(new ObjectMapper() {
   private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
           = new com.fasterxml.jackson.databind.ObjectMapper();

   public <T> T readValue(String value, Class<T> valueType) {
       try {
           return jacksonObjectMapper.readValue(value, valueType);
       } catch (IOException e) {
           throw new RuntimeException(e);
       }
   }
   //这里可以打印自己请求的json

   public String writeValue(Object value) {
       try {
           return jacksonObjectMapper.writeValueAsString(value);
       } catch (JsonProcessingException e) {
           throw new RuntimeException(e);
       }
   }
});

// This code sample uses the  'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.post("https://your-domain.atlassian.net/rest/api/2/issue")
  .basicAuth("email@example.com", "<api_token>")
  .header("Accept", "application/json")
  .header("Content-Type", "application/json")
  .body(payload)
  .asJson();

System.out.println(response.getBody());

这里可以打印自己发送的json脚本

复制代码
   //这里可以打印自己请求的json

   public String writeValue(Object value) {
       System.out.println("writeValue=====" + value);
       try {
           return jacksonObjectMapper.writeValueAsString(value);
       } catch (JsonProcessingException e) {
           throw new RuntimeException(e);
       }
   }

在这里给自己做个笔记

相关推荐
郑..方..醒1 天前
codex配置MCP连接并修改wiki、jira、数据库、观测云日志详细教程
ai编程·jira
PM老周6 天前
Jira、ONES、ClickUp 对比:哪款研发管理软件更适合中国研发团队?
jira·项目管理工具·ones·clickup·研发管理平台·研发流程管理
姚青&8 天前
流程管理平台 - JIRA
jira
PM老周18 天前
2026年 Jira 替代软件选型测评:支持项目管理与知识库管理的研发管理平台
项目管理·jira·项目管理工具·jira 替代方案
AC赳赳老秦19 天前
项目闭环管理:用 OpenClaw 对接 Jira / 禅道,实现需求 - 任务 - 进度 - 验收全流程自动化
运维·人工智能·python·自动化·devops·jira·openclaw
SL-staff21 天前
2026 企业项目管理工具选型:JIRA、飞书、JVS企业计划功能对比
项目管理·飞书·团队开发·jira·okr·jvs企业计划·决策流程
hillstream31 个月前
启用一个项目的RTM
jira
hillstream31 个月前
配置jira的创建问题screen的默认类型和顺序
jira
公众号:ITIL之家2 个月前
ITSM 工具选型指南 2026:ServiceNow、Jira、BMC 到底怎么选?
jira
xyzhan2 个月前
人工智能代理AI Agent如何自动化CRM、Jira、计费和Slack之间的工作流程
运维·人工智能·自动化·jira·ai agent