我试图从jira检索问题。我能够使用用户名和密码得到响应。但由于密码不断变化,我想使用API令牌进行身份验证。但我无法做到这一点。下面是我的代码:
public class JiraMetrics {
private static final String JIRA_URL = "https://jira.company.com";
private static final String JIRA_USERNAME = "username";
private static final String JIRA_password = "password";
public static void main(String[] args) throws URISyntaxException {
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI uri = new URI(JIRA_URL);
JiraRestClient client = factory.createWithBasicHttpAuthentication(uri,JIRA_USERNAME,JIRA_Password);
//Calling issues
Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("query");
for (Issue issue : searchJqlPromise.claim().getIssues()) {
System.out.println(issue.getKey());
}
}
我们可以使用API token调用而不是密码吗?
2条答案
按热度按时间v1l68za41#
您必须:
wgeznvg72#
我尝试了建议的答案,但失败了。我使用此页上的建议,通过传入承载/访问令牌的身份验证处理程序,使其工作:https://community.atlassian.com/t5/Jira-questions/How-do-I-use-a-personal-access-token-PAT-in-jira-rest-java/qaq-p/1859167