我能够通过JIRARestClient API连接到JIRA,也能够获取有关问题的信息,但是每当我尝试通过以下代码创建问题时,都会出现此错误“ RestClientException {statusCode = Optional.of(400 ),errorCollections = [ErrorCollection {status = 400,errors = {issuetype =必须为有效的问题类型},errorMessages = []}]}“
IssueRestClient issueClient = new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(baseUri, username, password).getIssueClient();
IssueType issueType = new IssueType(null, 0L, "bug", false, "my issue", null);
BasicProject basicProject = new BasicProject(null, "CPQ", 1L, null);
IssueInput newIssue = new IssueInputBuilder(basicProject,issueType,"Mopendra").build();
String issueCreated = issueClient.createIssue(newIssue).claim().getKey();
有人可以帮我吗?
答案 0 :(得分:2)
原因是您应该使用Jira中存在的有效问题类型并正确填充参数。您可以获取现有的问题类型,然后选择所需的一种。见
答案 1 :(得分:2)
请参考以下工作代码。这应该可以解决您的问题。
//调用方法createIssue
final String issueKey = myJiraClient.createIssue("YOUR_PRAJECT_NAME", 1L, "Issue created from Standalone App");
//方法声明
private String createIssue(String projectKey, Long iType, String issueSummary) {
IssueRestClient issueClient = restClient.getIssueClient();
BasicProject cpqProject = null;
IssueType issueType = null;
try {
final Iterable<BasicProject> projects = restClient.getProjectClient().getAllProjects().claim();
System.out.println("======================getting all projoects======================");
for (BasicProject project : projects) {
if(project.getKey().equalsIgnoreCase("cpq")) {
cpqProject = project;
}
}
Promise<Project> project = restClient.getProjectClient().getProject(projectKey);
for(IssueType type : (project.get()).getIssueTypes()) {
if(type.getName().equalsIgnoreCase("Bug")){
issueType = type;
}
}
} catch (Exception e) {
e.printStackTrace();
}
IssueInput newIssue = new IssueInputBuilder(cpqProject, issueType, issueSummary).build();
return issueClient.createIssue(newIssue).claim().getKey();
}