The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I write code to create a Project, issues and subtasks in Jira?

Hema Dhulab
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 31, 2015
 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Hema Dhulab
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 7, 2015

Thanks @Nic Brough for taking the time to answer my question.

Here are snippets of code that helped to create  a project , issue and subtask :

 


Create a project
Project p = ComponentAccessor.getProjectManager().createProject(name, key, description, lead, url, AssigneeTypes.PROJECT_LEAD);
ComponentAccessor.getPermissionSchemeManager().addDefaultSchemeToProject(p);
ComponentAccessor.getIssueTypeScreenSchemeManager().addSchemeAssociation(p,
        ComponentAccessor.getIssueTypeScreenSchemeManager().getDefaultScheme());
 
Create Issue of Task Type
IssueManager issueManager = ComponentAccessor.getIssueManager();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
MutableIssue issueObject = issueFactory.getIssue();
issueObject.setProjectObject(project);
    IssueType issueType = MyIssueType.getIssueType("Task");
    issueObject.setIssueTypeId(issueType.getId());
issueObject.setSummary(summary);
issueObject.setAssignee(authenticationContext.getUser().getDirectoryUser());
Date today = new Date();
issueObject.setCreated(new java.sql.Timestamp(today.getTime()));
issueObject.setDescription(description);
Issue issue;
    issue = issueManager.createIssueObject(authenticationContext.getUser().getDirectoryUser(), issueObject);

Create Subtasks
IssueManager issueManager = ComponentAccessor.getIssueManager();
        IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
        JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
        SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
        MutableIssue issueObject = issueFactory.getIssue();
        issueObject.setProjectObject(project);
        issueObject.setIssueTypeId(subtaskType.getId());
        issueObject.setParentId(parentIssue.getId());
        issueObject.setFixVersions(parentIssue.getFixVersions());
        issueObject.setAffectedVersions(parentIssue.getAffectedVersions());
        issueObject.setPriorityObject(parentIssue.getPriorityObject());
        issueObject.setSummary(summary);
        issueObject.setAssignee(authenticationContext.getUser().getDirectoryUser());
        Date today = new Date();
        issueObject.setCreated(new java.sql.Timestamp(today.getTime()));
        issueObject.setDescription(description);
Issue subTask;
                   subTask = issueManager.createIssueObject(authenticationContext.getUser().getDirectoryUser(), issueObject);
            subTaskManager.createSubTaskIssueLink(parentIssue,subTask,authenticationContext.getUser().getDirectoryUser());

   

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 31, 2015

There are three basic possibilities here:

You want to write an addon for Server versions of JIRA - addons like this can hook into the core of JIRA and do many powerful things, but can NOT be used on Cloud (unless Atlassian Cloud support adopt them, which is not easy to achieve).  Start at https://developer.atlassian.com/jiradev/

You want to write an addon for Cloud JIRA - you can use Atlassian Connect to do this - see https://developer.atlassian.com/static/connect/docs/latest/guides/introduction.html (development guides are linked off there, but I think it's worth a quick read of the concepts too)

You want to write stuff that will run outside JIRA and tell it to do stuff via REST - see https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-version-2-tutorial (there's more dry REST docs, but I prefer this one as a starting point)

TAGS
AUG Leaders

Atlassian Community Events