连接JIRA并检索信息



我有一个任务是通过Java从JIRA帐户中检索一些信息。我下载了使用Java的Jira API,但我不知道如何使它工作。我必须把我的用户名和密码传给某个地方登录,然后从我想要的项目中检索我想要的信息。

JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI uri = new URI(JIRA_URL);
JiraRestClient client = factory.createWithBasicHttpAuthentication(uri,  JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
// Invoke the JRJC Client
Promise<User> promise = client.getUserClient().getUser("admin");

// Here I am getting the error!!
User user = promise.claim();
///////////////////////////////////////
// Print the result
System.out.println(String.format("Your admin user's email address is: %srn", user.getEmailAddress()));
// Done
System.out.println("Example complete. Now exiting.");
System.exit(0);

上面的代码不起作用,因为如果我传递了错误的密码和错误的用户名,就会显示相同的结果。我必须知道如何正确连接到JIRA,并从那里检索JSON中的一些信息!感谢您抽出时间!

这是错误

Caused by: com.atlassian.jira.rest.client.api.RestClientException: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 9 of 

我认为您没有访问Jira的必要权限,您必须使用具有正确权限的帐户连接Jira!

我唯一能想到的就是你发送的信用不正确。尝试使用电子邮件地址,而不仅仅是"admin"。

以下是一些可能有所帮助的代码:https://github.com/somaiah/jrjc

我检查了一个问题,但获取用户信息会类似。

您可以使用下面的代码来获取结果。请记住,我在我的gradle项目中使用了这个,我正在下载JRCJ 的所有依赖项

import com.atlassian.jira.rest.client.api.JiraRestClientFactory
import com.atlassian.jira.rest.client.api.domain.User
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
import com.atlassian.util.concurrent.Promise
/**
 * TODO: Class description
 *
 * on 20 Jul 2017
 */
class Jira {
  private static final String JIRA_URL = "https://JIRA.test.com"
  private static final String JIRA_ADMIN_USERNAME = "ABCDE"
  private static final String JIRA_ADMIN_PASSWORD = "******"
  static void main(String[] args) throws Exception
  {
    // Construct the JRJC client
    System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD))
    JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory()
    URI uri = new URI(JIRA_URL)
    JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD)

    // Invoke the JRJC Client
    Promise<User> promise = client.getUserClient().getUser(JIRA_ADMIN_USERNAME)
    User user = promise.claim()
    // Print the result
    System.out.println(String.format("Your user's email address is: %srn", user.getEmailAddress()))
    // Done
    //System.out.println("Example complete. Now exiting.")
    //System.exit(0)
  }
}

最新更新