How can i create or update issues within a plugin?
i can get all the issues with JQL and i want to update (or also create a new one) some of them, if the data i get from outside are not the same
What kind of plug-in are you developing - Server or Cloud?
For Server you can use the Java APIs - take a look at IssueService. For Cloud you need to use the REST APIs. Let me know if you have a more concrete question.
i am developing for server
i had a look on IssueService and build this code. Am i on the right track?
IssueInputParameters parameters = issueService.newIssueInputParameters(); parameters.setDescription("description"); //example // item.getId() gets the issueId that have to be updated UpdateValidationResult updateResult = issueService.validateUpdate(currUser, new Long(item.getId()), parameters); //updates the issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's the way to do it, you just need to add the actual update invocation:
issueService.update(currUser, updateResult);
The pattern for creating an issue is the same - validateCreate() then create().
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks a lot, updating is working
but i have some problem creating a new issue.. I add the IssueInputParameters like that, but it do not work:
private IssueInputParameters addParameters(IssueInputParameters par, Long projId) { par.setProjectId(projId); par.setDescription(getDescriptionString(item)); return par; }
have i to do anything else?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to call issueService.validateCreate() and then create(). What do you mean by "it does not work"? Is there an error thrown?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it works now, i think the problem was i only set the project-id and the description.. after i set all the required fields (summary, issuetype, reporter-id) it created a new issue
Another question:
how can i set an ApplicationUser? now i set him as the logged-in one.. but later it should be always the same user with admin-permissions..
can i do it that way:
ApplicationUser currUser = userManager.getUserByName("admin");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you could do that, but you need to make sure that user has sufficient permissions to create issues. Also hardcoding users in your code has its own drawbacks - the user name may change, the user may get deleted, etc. If you really want to have a service user which will be used to create issues, maybe you should think about making that user selectable via a configuration UI so that at least it's not hardcoded in you plug-in code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok thanks a lot for your detailed answer, i will regard this.
now i had an other prolbem: i want to set the Components and the Status of the IssueInputParameters. i do it like that:
IssueInputParameters par; par.setComponentIds(getComponents(item)); par.setStatusId(getStatusId(item)); getComponents(Object item) { // gets all the components from Jira, parse them with a List from the item-object, if there is a match save it to a Long-Array and after return the Long-Array } getStatusId(Object item) { // gets all statuses from Jira and parse them with the one from the item-object, returns a String with the ID of the Status from Jira }
The methods "getComponents" and "getStatusId" return a valid Long-Array and String, i proof that... the components exist in Jira, i could select them directly from JIRA ..
Maybe you have an idea what i do wrong
thanks for your great help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, I don't think you can set the status ID like that - you'll need to transition the issue to that status after the issue is created.
You didn't mention what goes wrong - does validateCreate return errors or just the issue is created with no components?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
components work now. First I create an issue without components and after i update that issue with the components.. that works fine now
i try the same with the status but it do not change the status (the status i want to set is valid: f.e.: i want to set it from "Open" to "In Progress"). there are no errors about that
Another thing.. now my plugin is a Scheduler that runs every X minutes.. updating issues work but if it should create a new issue, i get this error:
Errors: {pid=Anonymous users do not have permission to create issues in this project. Please try logging in first.}
so i think i have to tell my plugin to login a user that can create issues.. but how can i do that? how can i login a user within a plugin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.