• Community
  • Products
  • Jira
  • Questions
  • How to automatically create a confluence page based of a template when a jira subtask is created and also link to it, through a custom script in script runner?

How to automatically create a confluence page based of a template when a jira subtask is created and also link to it, through a custom script in script runner?

I have a groovy script in which I am dynamically creating subtasks based on some conditions. I want each of these subtasks to have a link to a confluence page automatically created, from a template(which I have already created). How do I do that? No other add-on than script runner is allowed. I have seen many such questions online, but none of them provide with a way to do it with scriptrunner and using a confluence template .

4 answers

This widget could not be displayed.

So, it sounds like you need to do two things when the sub-task is created:

1) Create a new page from a template in Confluence

There does appear to be a REST endpoint in Confluence's API that lets you create an instance of a template with a POST request. You can call it using the app link configuration; see the documentation on interacting with other Atlassian apps.

If Confluence's current REST endpoint doesn't cut it, you could use ScriptRunner for Confluence to add a scripted REST Endpoint that you can call from JIRA.

2) Link the sub-task to the newly created Confluence page

You could simply embed a JIRA macro in the new Confluence page. Assuming JIRA and Confluence are linked, this should create a remote link in JIRA as well. See the docs on interacting with confluence from JIRA.

You could also create the remote link inside JIRA using the Java API for it.

Steven Behnke Community Champion Nov 30, 2016

Hey sweet! That Template API is new! 

Edit: Oh BOO it's Cloud-only for now.

Bummer! Just to clarify, do you have ScriptRunner for Confluence, or just ScriptRunner for JIRA? Because if you've got SR for confluence, I believe you can create a page from a template via the Java API using the CreatePageFromTemplateAction class... don't have an example handy, but I can cook one up if SR for Conf is an option for you.

Steven Behnke Community Champion Dec 07, 2016

I'd love to explain my use-case if you have some time, even just to share. If, of course, you talking to me? smile

@Steven Behnke - sure, I'll talk. Though maybe you should open your own question with your particular details, so we don't distract from Shagufta's need?

This widget could not be displayed.
Steven Behnke Community Champion Nov 22, 2016

Confluence still hasn't exposed the Template feature to the REST API - This is probably why you don't see any documentation on this topic. 

This leaves a few options – 

  • Hardcode the HTML for the page within your groovy script
  • Copy an existing page within Confluence, within your groovy script
  • Use ScriptRunner for Confluence to expose the Template feature to REST API and then leverage it within your groovy script

 

Can you please give an example of how the 3rd option can be done?

Hi all!

I have the same problem and so little information on this subject. Shagufta, tell me please, do you resolve your task?

This widget could not be displayed.

I believe if Jenkins is being used via some integration Jenkins can be used to trigger a page from template.. I don't have the details to hand. Though know it's possible..

This widget could not be displayed.

Has anyone found a REST or Scriptrunner solution for this yet?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

128 views 2 0
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