简体   繁体   English

如何使用JIRA REST Java Client创建子任务

[英]How to create subtasks using JIRA REST Java Client

Is there a way to create a subtask using JRJC v1.0? 有没有办法使用JRJC v1.0创建子任务? I've been unable to find any good documentation on this. 我一直找不到与此相关的任何文档。 Any sample codes out there? 有任何示例代码吗?

It seems like it's not supported via the library but possible using straight REST API. 似乎该库不支持它,但是可以使用直接的REST API。

JIRA v5.1.5 JIRA v5.1.5

I was able to put together the below code that worked. 我能够将下面的代码组合在一起。

    IssueInputBuilder issueBuilder = new IssueInputBuilder("Project1", 5L);//5 is the id for subtask type. You can know the id of subtask type by querying this REST api /rest/api/2/issue/createmeta
    issueBuilder.setDescription(">> Test Description");
    issueBuilder.setSummary("Test summary");
    issueBuilder.setProjectKey("Project1");
    Map<String, Object> parent = new HashMap<String, Object>();
    parent.put("key", "SOMEISSUE-234");
    FieldInput parentField = new FieldInput("parent", new ComplexIssueInputFieldValue(parent));

    Map<String, Object> customField = new HashMap<String, Object>();
    customField.put("value", "someValue");//This is some custom field value on the subtask
    customField.put("id", "12345");//This is the id of the custom field. You can know this by calling REST GET for a manually created sub-task

    issueBuilder.setFieldInput(parentField);
    issueBuilder.setFieldValue("customfield_12345",  new ComplexIssueInputFieldValue(customField));//here again you have to query an existing subtask to know the "customfield_*" value

    com.atlassian.jira.rest.client.domain.input.IssueInput issueInput = issueBuilder.build();
    BasicIssue bIssue = restClient.getIssueClient().createIssue(issueInput, pm);    
    System.out.println(">>> " + bIssue.getKey());

You create an issue as you normally would ( example ), but set the issue type to the required subtask type. 您可以像往常一样创建问题( 示例 ),但是将问题类型设置为必需的子任务类型。 Then, to link the subtask to it's parent use linkIssue , something like: 然后,使用linkIssue将子任务链接到其父任务,例如:

LinkIssuesInput linkIssuesInput = new LinkIssuesInput("TST-1", "TST-2", "jira_subtask_link", Comment.valueOf("simple comment"));
issueClient.linkIssue( linkIssuesInput , pm);

I haven't tested it myself, I've used the XML-RPC in old JIra, and python-jira in new ones. 我自己还没有测试过,我在旧的JIra中使用了XML-RPC ,在新的JIra中使用了python-jira The full API is available here 完整的API 在这里可用

The REST API http://docs.atlassian.com/jira/REST/latest/#id326540 has a comment: REST API http://docs.atlassian.com/jira/REST/latest/#id326540带有注释:

Creating a sub-task is similar to creating a regular issue, with two important differences: 创建子任务类似于创建常规任务,但有两个重要区别:

the issueType field must correspond to a sub-task issue type (you can use /issue/createmeta to discover sub-task issue types), and you must provide a parent field in the issue create request containing the id or key of the parent issue. issueType字段必须对应于子任务问题类型(可以使用/ issue / createmeta查找子任务问题类型),并且必须在问题创建请求中提供一个父字段,其中包含父问题的ID或键。

So I think that the regular createIssue method should work, but you need to make sure you have passed in an extra FieldInput object constructed with ("parent", "ABC-123") 因此,我认为常规的createIssue方法应该可以工作,但是您需要确保已传入由(“ parent”,“ ABC-123”)构造的额外FieldInput对象。

I'd be surprised if linking using the subtask link type actually works. 如果使用子任务链接类型的链接确实有效,我会感到惊讶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM