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

在这里给自己做个笔记

相关推荐
CodeCraft Studio14 天前
ONLYOFFICE Jira 集成应用程序 4.0.0 发布,含新的文件格式支持等多个重大更新!
pdf·powerpoint·onlyoffice·jira
MaisieKim_2 个月前
Jira、PingCode、Redmine等18款缺陷管理工具对比评测
jira·redmine·pingcode
hyhrosewind3 个月前
基础(项目管理工具:JIRA、禅道)
jira·缺陷管理·禅道·项目管理工具·jira安装·禅道安装
测试渣3 个月前
JIRA/Xray测试管理工具的最佳实践:从基础到高阶的全场景指南
测试工具·自动化·jira
公众号:ITIL之家3 个月前
ServiceNow vs Jira:哪个更适合中国式ITIL落地?
jira
龙智DevSecOps解决方案3 个月前
汽车行业敏捷开发实践:基于Atlassian工具链的全流程解决方案(Jira、Confluence、Jira Service Management等)
atlassian·敏捷流程·jira·汽车软件开发
hillstream34 个月前
jira操作笔记
笔记·jira
龙智DevSecOps解决方案4 个月前
需求管理工具选型指南:Jama Connect +Jira vs Word/Excel+Jira
项目管理·atlassian·需求管理·jira·jamaconnect
跟YY哥学Jira4 个月前
解密 Atlassian Cloud:创新驱动的项目管理之道
经验分享·项目管理·微信公众平台·jira·jira认证
唐古乌梁海4 个月前
【jira】用到几张表
jira