Automatically create a page under project on confluence when a JIRA issue is created.

SUNIL KUMAR CHINNAMGARI January 8, 2012


Is there a way to created pages automatically on confluence under a project when an issue is created on JIRA under the project? Currently, in our evaluation setup we are creating manual pages on confluence but this does not appear to be a viable solution for us in long term :(

6 answers

3 votes
JamieA
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 Leaders.
January 8, 2012

Update: see https://jamieechlin.atlassian.net/wiki/display/GRV/Interacting+with+Confluence+from+JIRA

Old answer from 2.5 years ago:

It doesn't take much programming. Eg, using the script runner plugin, set a script post-function on issue create, the script might be:

package examples

import org.swift.common.soap.confluence.ConfluenceSoapServiceServiceLocator

def locator = new ConfluenceSoapServiceServiceLocator()
def service = locator.getConfluenceserviceV2(new URL("http://confluence.acme.com"))
def token = service.login("admin", "password")
def page = service.getPage(token, "MYSPACE", issue.summary)
page.content = issue.description
service.updatePage(token, page)

I haven't tested that and haven't used the confluence SOAP API for a while so it might not work. Also I used the compiled stubs from Bob's CLI distro, hence the org.swift, but I could have compiled them myself. To work this needs the confluence-soap-4.0.0.jar from Bob's CLI in the WEB-INF/lib of jira (or compile the stubs yourself and add the jar).

A good enhancement would be to use applinks rather hard-wire the admin password, and maybe to keep the confluence page up to date with a listener... although that would seem to defeat the purpose come to think of it.

 

Bob Swift OSS (Bob Swift Atlassian Apps)
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 Leaders.
January 9, 2012

The jar Jamie references is available at Confluence SOAP Library.

SUNIL KUMAR CHINNAMGARI January 9, 2012

Thanks Jamie and Bob. Unfortunately, I do not have any webservices / J2EE programming experience. I shall seek help from my collegues to accomplish this. Thanks!

Pramod Kutty April 16, 2014

Is there a way to not have a password in the groovy script and use the logged in user. I mean use the SSO

1 vote
Sherif Mansour
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 9, 2012

In JIRA 5.0 (coming soon), you've got the ability to link an issue to Confluence pages: http://confluence.atlassian.com/display/JIRA/JIRA+Remote+Issue+Links

You
could create a plugin that when a new issue is created, Confluence pages are created and the linked to the issue

Out of curiosity, what are you using this for? What is the business scenario which wants this? For specs? Other things?

SUNIL KUMAR CHINNAMGARI January 9, 2012

The business case is very simple -

We want to track the workflow of issue on JIRA and at each step of the workflow we have exit criteria defined which are mostly documents.Ofcourse, some comments revisions go on these docs. We want to be able to put all the docs in confluence ten reference those links on JIRA issue. The current design of Jira-Confluence does not auto-create pages when jira issues are created so there is some level of resistance to adopt confluence.

Another capability is to be able to come up with auto-screens as defined on Jira workflow on confluence. At the current setting, I do not see this option too. What are your thoughts?

0 votes
Dmitri Abrosov [Teamlead] January 20, 2015

Hi, can anybody help me with that task? I've added Custom script post-function with the following code on the transition:

package examples.docs
 
import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
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
 
/**
 * Retrieve the primary confluence application link
 * @return confluence app link
 */
def ApplicationLink getPrimaryConfluenceLink() {
    def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService.class)
    final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class);
    conflLink
}
 
// the issue provided to us in the binding
Issue issue = issue
 
// if you don't want to create confluence pages based on some criterion like issue type, handle this, eg:
//if (! issue.issueTypeObject.name == "Bug") {
//    return
//}
 
def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up
 
def authenticatedRequestFactory = confluenceLink.createAuthenticatedRequestFactory()
 
// set the page title - this should be unique in the space or page creation will fail
def pageTitle = issue.key + " Discussion"
def pageBody = """h3. ${issue.summary}
{quote}${issue.description}{quote}
Yada yada, use this page to discuss the above...
"""
 
def params = [
    type: "page",
    title: pageTitle,
    space: [
        key: "DS" // set the space key - or calculate it from the project or something
    ],
    // if you want to specify create the page under another, do it like this:
    // ancestors: [
    //     [
    //         type: "page",
    //         id: "14123220",
    //     ]
    // ],
    body: [
        wiki: [
            value: pageBody
        ]
    ]
]
 
authenticatedRequestFactory
    .createRequest(Request.MethodType.POST, "rest/api/content")
    .addHeader("Content-Type", "application/json")
    .setRequestBody(new JsonBuilder(params).toString())
    .execute(new ResponseHandler<Response>() {
        @Override
        void handle(Response response) throws ResponseException {
            if(response.statusCode != HttpURLConnection.HTTP_OK) {
                throw new Exception(response.getResponseBodyAsString())
            }
        }
})

DS - is the key of Demo space in Confluence. But pages are not created on the issue transition. Why?

JamieA
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 Leaders.
January 21, 2015

Check your logs and post anything relevant?

Hasna March 12, 2020

Hi @JamieA 

 

Can we create pages to the confluence that is not connected as primary application links

0 votes
Sorin Sbarnea (Citrix)
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 Leaders.
July 8, 2012

Had you picked a solution yet? I am facing the same problem but in my case I do have an ancient jira 3.x plugin that was doing this and I need to replace it with something else because it is not compatible with newer jira versions and also it is too hard to maintain or configure.

0 votes
Nagmani Nagmani January 19, 2012

Hey BoB I am facing still problems in implementing your code in jira for automated page creation in confluence.

Please help me by elaborating how to implement this code in jira. I have tried the wayyou have mentioned but I didnt get how to apply script runner in the project..??

Please Clarify

Bob Swift OSS (Bob Swift Atlassian Apps)
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 Leaders.
January 19, 2012

I think you are talking about Jamie's answer using script runner. I can't help you there other than to say follow the instructions he provided. My non-programming solution is not available at this time. I will post here when it is.

JamieA
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 Leaders.
January 19, 2012

Try reading the comprehensive script runner documentation. If you are not technical I'd advise you to wait for Bob's non-programming solution.

Fabrizio Galletti
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 Leaders.
January 20, 2013

Any news Bob?

i will check script too

Bob Swift OSS (Bob Swift Atlassian Apps)
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 Leaders.
January 20, 2013

Yes, CLI Plugin for JIRA. It has been available for some time, but I lost track of this post :(.

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
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 Leaders.
January 8, 2012

Not that I am aware of without programming. I am working on a something similar (without a programming requirement), but it will not be available for a while.

SUNIL KUMAR CHINNAMGARI January 9, 2012

Thanks Bob. I wish your plugin is available at the earliest. I am sure everyone wants to use it.

Sebastian Nitu September 1, 2013

Hey Bob,

How can I use your CLI Plugin for JIRA in order to generate a Confluence article whenever I create an Issue in JIRA?

Thanks!

Bob Swift OSS (Bob Swift Atlassian Apps)
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 Leaders.
September 1, 2013

The steps are similar to How to create subtasks on initial issue create, except you will use the CLI action post function to run the storePage action.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events