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 天前
Kanass实战解读(16) - 如何通过评审,有效保障需求和用例的质量
jira·禅道·开源项目管理工具
Wpa.wk4 天前
软件测试的流程-介绍
经验分享·测试工具·jira·测试流程·测试流程管理
一叶轻舟随风行10 天前
kanass实战教程系列(10) - 如何进行缺陷管理
jira·禅道·项目管理工具·开源项目管理工具
一叶轻舟随风行10 天前
kanass实战教程系列(11) - 如何进行迭代管理
jira·禅道·项目管理工具
一叶轻舟随风行14 天前
kanass实战教程系列(4) - 产品经理如何使用kanass有效管理需求
jira·禅道·项目管理工具
一叶轻舟随风行14 天前
kanass实战教程系列(5) - 开发团队如何通过kanass有效管控开发任务
jira·禅道·项目管理工具
一叶轻舟随风行14 天前
kanass实战教程系列(6) - 测试团队如何通过kanass管理跟踪用例与缺陷
jira·禅道·项目管理工具
一叶轻舟随风行15 天前
Kanass实战教程系列(1) - 安装与配置
jira·项目管理工具
一叶轻舟随风行17 天前
一文掌握,kanass安装与配置
jira·禅道·项目管理工具·ones
一叶轻舟随风行17 天前
拒绝繁琐,介绍一款简洁易用的项目管理工具-Kanass
jira·禅道·项目管理工具