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);
       }
   }

在这里给自己做个笔记

相关推荐
钉钉项目Teambition10 天前
Jira Cloud涨价5%-20%,钉钉项目Teambition成优选替代
钉钉·jira·teambition
Wninacc2 个月前
jira敏捷开发管理工具视频教程Confluence工作流协同开发(2024)
java·javascript·eclipse·敏捷流程·jira
龙智DevSecOps解决方案2 个月前
龙智Atlassian解决方案实践案例:集成Jira、Confluence、JSM,助力某汽车行业客户实现高效项目管理
车载系统·atlassian·jira
龙智DevSecOps解决方案2 个月前
Atlassian Intelligence工具集解析:从自然语言到JQL处理,从虚拟代理到AI摘要、编辑器中的生成式AI等,全方位提升团队协作效率
人工智能·atlassian·软件需求·jira
baidu_169924413 个月前
JIRA的高级搜索JIRA Query Language(JQL)详解
jira
龙智DevSecOps解决方案3 个月前
Jira实践案例分享:小米集团如何通过API请求优化、数据治理与AI智能客服等,实现Jira系统的高效运维
运维·人工智能·jira
联蔚盘云3 个月前
DevOps CMDB平台整合Jira工单
运维·devops·jira
007php0073 个月前
如何生成自定义二维码和实现安全便捷的扫码登录功能以及对接企业微信API
java·开发语言·经验分享·redis·笔记·git·功能测试·jmeter·其他·nginx·安全·百度·ajax·ci/cd·docker·微信·架构·golang·系统架构·单元测试·centos·github·jenkins·php·erlang·企业微信·postman·sass·课程设计·微信公众平台·safari·facebook·oneapi·twitter·composer·jira·paddle·新浪微博·lvs·segmentfault·微信开放平台
yanlaifan4 个月前
Jira系统基本介绍
jira
007php0074 个月前
构建智慧小程序平台——系统架构设计与应用探索
java·大数据·经验分享·redis·笔记·git·功能测试·gpt·selenium·jmeter·其他·nginx·安全·百度·docker·微服务·微信·云原生·小程序·架构·golang·系统架构·测试用例·php·负载均衡·压力测试·文心一言·课程设计·ai编程·微信公众平台·模块测试·测试覆盖率·facebook·oneapi·twitter·composer·jira·paddle·新浪微博·segmentfault·微信开放平台