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


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

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.

 

The jar Jamie references is available at Confluence SOAP Library.

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!

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

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?

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?

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.

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

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!

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.

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

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.

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

Any news Bob?

i will check script too

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

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.

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?

Check your logs and post anything relevant?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

781 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you