Automatically create a page under project on confluence when a JIRA issue is created.
Asked by SUNIL KUMAR CHINNAMGARI:

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 :(


Answers:
author: JamieA
body: *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](https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner) plugin, set a script post-function on issue create, the script might be:

```
package examplesimport org.swift.common.soap.confluence.ConfluenceSoapServiceServiceLocatordef 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.descriptionservice.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.

comments: author: Bob Swift (personal)
body: The jar Jamie references is available at [Confluence SOAP Library](https://studio.plugins.atlassian.com/wiki/display/CSOAPLIB).


author: SUNIL KUMAR CHINNAMGARI
body: 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!


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


author: Sherif Mansour
body: 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](http://confluence.atlassian.com/display/JIRA/JIRA+Remote+Issue+Links%3Cbr%3E%3Cbr%3EYou) 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?

comments: author: SUNIL KUMAR CHINNAMGARI
body: 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?


author: Dmitri Abrosov [Teamlead]
body: 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.ApplicationLinkimport com.atlassian.applinks.api.ApplicationLinkServiceimport com.atlassian.applinks.api.application.confluence.ConfluenceApplicationTypeimport com.atlassian.jira.issue.Issueimport com.atlassian.sal.api.component.ComponentLocatorimport com.atlassian.sal.api.net.Requestimport com.atlassian.sal.api.net.Responseimport com.atlassian.sal.api.net.ResponseExceptionimport com.atlassian.sal.api.net.ResponseHandlerimport 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 bindingIssue 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 faildef 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&lt;Response&gt;() {        @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?

comments: author: JamieA
body: Check your logs and post anything relevant?


author: Hasna
body: Hi [@JamieA](/t5/user/viewprofilepage/user-id/781456)

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


author: Sorin Sbarnea (Citrix)
body: 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.


author: Nagmani Nagmani
body: 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

comments: author: Bob Swift (personal)
body: 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.


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


author: Fabrizio Galletti
body: Any news Bob?

i will check script too


author: Bob Swift (personal)
body: Yes, [CLI Plugin for JIRA](https://bobswift.atlassian.net/wiki/display/JCLIP). It has been available for some time, but I lost track of this post :(.


author: Bob Swift (personal)
body: 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.

comments: author: SUNIL KUMAR CHINNAMGARI
body: Thanks Bob. I wish your plugin is available at the earliest. I am sure everyone wants to use it.


author: Sebastian Nitu
body: 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!


author: Bob Swift (personal)
body: The steps are similar to [**How to create subtasks on initial issue create**](https://bobswift.atlassian.net/wiki/display/CSOT/How+to+create+subtasks+on+initial+issue+create), except you will use the [CLI action post function](https://bobswift.atlassian.net/wiki/display/JCLIP/CLI+Plugin+for+JIRA) to run the [**storePage**](https://bobswift.atlassian.net/wiki/display/CSOAP/Documentation#Documentation-storePage) action.


Tags: integration

jira