Work with Projects
Create, modify, and archive projects using HAPI, with code examples for each operation.
Migrating to Jira Cloud? This feature is available in Cloud. |
Creating a new project
Creating a project with default values
You can create a new project as follows:
Projects.create("TIS", "Teams in Space")Setting details when creating a new project
When you create a project, some assumptions are made about fields such as the project lead (set to the current user), the project type (set to business), and the default assignee for the project (set to Unassigned). You can set these values, as well as optional values such as the description or the URL, when you create the project. For example:
Projects.create("TIS", "Teams in Space") {
projectLead = 'admin'
projectType = "business"
description = "This is a new project!"
url = "https://google.com"
setDefaultAssigneeToProjectLead()
avatarId = 10001
}Creating a project using a template
You can create a new project using a template as follows:
Projects.create("TIS", "Teams in Space") {
projectLead = 'admin'
projectTemplateKey = "com.pyxis.greenhopper.jira:basic-software-development-template"
}The project templates available to you are provided through completions. You'll notice the names are the same as those you see when you create a project through Jira.
Retrieving a project by key
You can retrieve a project by key as follows:
Projects.getByKey("TIS")Updating a project
You can update a project as follows:
Projects.getByKey("TIS").update {
key = "TEAM"
name = "Team project"
description = "This is an updated project!"
setDefaultAssigneeToUnassigned()
projectCategory = "Backend projects"
}Updating the project type
You can update the project type as follows:
Projects.getByKey("TIS").update {
projectType = "service_desk"
}Archiving a project
You can archive a project as follows:
def project = Projects.getByKey("TIS")
project.archive()Deleting a project
You can delete a project as as follows:
Projects.getByKey("TIS").delete()