You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Create a Jira Project When a Confluence Space is Created

Overview

Confluence and Jira can be related to one another through application links. With linked instances, you can perform actions in Jira by running scripts from Confluence and vice-versa. Use this script to create a project in Jira when a Confluence space is created.

Example

I am a technical writer using Confluence to publish documentation for several software projects. Each documentation set is stored in a corresponding space. Using this script, I can create a new project in the linked Jira instance every time I create a new space in Confluence, saving me the time of manually creating Jira projects for each new documentation set.

Good to Know

  • Create an application link to link Jira and Confluence.
  • Associate this script with the SpaceCreateEvent event listener.

Requirements

  • Jira Jira (7.7 - 8.6)
  • Confluence Confluence (6.6 - 7.10)
  • ScriptRunner for Jira ScriptRunner for Jira (5.6.14)
  • ScriptRunner for Confluence ScriptRunner for Confluence (6.21.0)
    
import com.atlassian.applinks.api.ApplicationLinkService import com.atlassian.applinks.api.application.jira.JiraApplicationType import com.atlassian.confluence.event.events.space.SpaceCreateEvent import com.atlassian.sal.api.component.ComponentLocator import com.atlassian.sal.api.net.Response import com.atlassian.sal.api.net.ResponseException import com.atlassian.sal.api.net.ResponseHandler import groovy.json.JsonBuilder import static com.atlassian.sal.api.net.Request.MethodType.POST // Get required components def appLinkService = ComponentLocator.getComponent(ApplicationLinkService) def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType) def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory() def _event = event as SpaceCreateEvent def space = _event.space // Define the request body to creta a new project def input = new JsonBuilder([ projectTypeKey : "business", projectTemplateKey: "com.atlassian.jira-core-project-templates:jira-core-task-management", name : space.name, key : space.key, lead : _event.space.creator.name, ]).toString() // Create and execute the request def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/project") .addHeader("Content-Type", "application/json") .setEntity(input) request.execute(new ResponseHandler() { @Override void handle(Response response) throws ResponseException { if (response.statusCode != 200) { log.info("Jira project successfully created") } else { log.error("Creating Jira project failed: ${response.responseBodyAsString}") } } })
Discovered an issue? Report it here

Suggested for you