如何使用Java Jira Rest Client

时间:2017-02-27 15:56:58

标签: jira-rest-java-api

我正在尝试设置海关字段,同时我正在使用Java Jira Rest Client创建一个Jira实例。

下面是我正在尝试实现的自定义字段的XML表示,其中“DATAOBJECT”是多选项中的项目:

<customfield id="customfield_10730" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
    <customfieldname>Environnements</customfieldname>
        <customfieldvalues>
            <customfieldvalue key="13044">
                <![CDATA[ DATAOBJECT]]>
            </customfieldvalue>
        </customfieldvalues>
</customfield>

下面是我的Java代码,它允许我在Jira中创建一个实例但没有自定义字段。

JiraRestClientFactory restClientFactory = new AsynchronousJiraRestClientFactory();
try {

    JiraRestClient restClient = restClientFactory.createWithBasicHttpAuthentication(new URI("http://JIRA_DOMAIN"), "Username", "Passwd");           
    IssueRestClient i = restClient.getIssueClient();            
    IssueInputBuilder issueBuilder = new IssueInputBuilder("projectKey", issueTypeID));
    issueBuilder.setSummary("description");
    issueBuilder.setFieldValue("customfield_10730", "DATAOBJECT");
    IssueInput issue = issueBuilder.build();

    Promise<BasicIssue> promise = i.createIssue(issue);
    try 
    {
        BasicIssue basicIssue = promise.get();
        System.out.println(basicIssue.getId());
        restClient.close();
    } 
    catch (Exception e) 
    {
        System.out.println(e.getMessage());
    } 

} 
catch (URISyntaxException e) 
{
    System.out.println(e.getMessage());
}

此代码不起作用,我正在使用Java Jira Rest Client 2.0.0-m31。 有人可以告诉我这里出了什么问题吗?

提前致谢。

3 个答案:

答案 0 :(得分:0)

对于多选自定义字段:

ComplexIssueInputFieldValue value = ComplexIssueInputFieldValue.with("value", "DATAOBJECT");
issueBuilder.setFieldValue("customfield_10730", Collections.singletonList(value));    

对于单选字段:

issueBuilder.setFieldValue("customfield_10730", ComplexIssueInputFieldValue.with("value", "DATAOBJECT"));

(使用jira-rest-java-client-api和jira-rest-java-client-core v.4.0.0为我工作)

答案 1 :(得分:0)

试试这个:

String []values = {"Value1","Value2"}; 
    String custonFieldId = "customfield_10730";
    List<ComplexIssueInputFieldValue> fieldList = new ArrayList<ComplexIssueInputFieldValue>(); 

     for(String value : values){
          Map<String, Object> aMap = new HashMap<String, Object>();
          aMap.put(null,value); 
          //If you also need to pass an id
          //aMap.put(id,value);  
          //fieldList.add(aMap);
          fieldList.add(aMap);
}
   issue.setFieldValue( custonFieldId , fieldList);

我希望这有助于某人!

答案 2 :(得分:0)

......这对我有用。 customfield_16681是多选字段

import net.rcarz.jiraclient.*;
import org.json.JSONObject;
import java.util.ArrayList;

JSONObject entityObject = new JSONObject();
entityObject.put("id", "17891");
Issue newIssue = jira.createIssue("ProjectID", "Bug")
                .field(Field.SUMMARY, "Test of create Jira")
                .field(Field.DESCRIPTION, "Test of create Jira desc")
                .field(Field.ASSIGNEE, "Roman")
                .field(Field.FIX_VERSIONS, new ArrayList() {{
                    add("your version");}})                
                .field("customfield_16681", new ArrayList<Object>(){{  add(entityObject);}})
                .execute();
        System.out.println(newIssue);

pom依赖:

<dependency>
    <groupId>net.rcarz</groupId>
    <artifactId>jira-client</artifactId>
    <version>0.5</version>
    <scope>compile</scope>
</dependency>