Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automating the creation of a Confluence page linked to a Jira ticket

One of the questions I've seen frequently is how can you use native Jira automation to create a Confluence page and link it to a Jira ticket. It's something that I was struggling with myself; we had a requirement from a new team to automatically create a new Confluence page for every story that is created.

I spent some time with ScriptRunner, but eventually found a native way to do it. It's not the prettiest, and there's a lot you could do to extend this as far as content of the page, but this will give you the basic action of creating a page and linking it to a newly-created ticket.

  1. Go to Project Settings -> Automation and create a new rule.
  2. Choose your trigger. In my example, I'm using the Issue Created trigger, but this should work with any of the available Jira triggers.
    automationStep1.png

  3. Add any conditions you'd like to have; in this case I'm having the rule run only when tasks are created.
    automationStep2.png

  4. Add your action, which will be Send Web Request.
    automationStep3b.png

Here's where the fun starts. You'll need to enter the following information:

  1. REST API call to create a page; it will be https://<your-instance-url>/wiki/rest/api/content

  2. A Basic Authorization header. Detailed instructions for creating this are here. The quick format is to base-64 encode a string composed of "useremail:usertoken".

  3. The HTTP method; it will be POST for creation.

  4. The webhook body. Because we're going to want to create a link, we're going to choose Custom Data.
    automationStep3.png

Now you'll need to get some information from Confluence. Create a new page using the old editor (this is important*) and insert a Jira macro that displays a single ticket (or find an existing page that has one.)

In Read mode, click the three dots menu, then go to Advanced Details -> View Storage Format.
automation6.png

You'll see a page that looks like this:
automationMacro.png

Copy the text into a text editor. You're going to have to do some formatting to make it work with the webhook, and it's easier to do your editing in a full screen app than the small text box on the automation rule screen.

You'll need to add escape slashes to all the quoted values, add newline characters after each line break, and replace the "key" parameter with the smart value your automation rule has in context. If you're using the Issue Create trigger, this would be {{issue.key}}.

You'll then copy all of it into the storage value element of the json block that will be your webhook body. The entire chunk goes inside double quotes (which is why you need to escape all the existing quotes in the macro code.) Mine looks like this.

{
"type":"page",
"title":"{{issue.key}} {{issue.summary}}",
"space":{"key":"MPS2U"},
"body":{
"storage":{
"value":"<ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\" ac:macro-id=\"71c4c2a3-db0b-499f-816d-64395f485435\">\n <ac:parameter ac:name=\"server\">System JIRA</ac:parameter>\n <ac:parameter ac:name=\"columns\">key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter>\n <ac:parameter ac:name=\"serverId\">c5a16fc3-0742-303f-b02a-822c531694b6</ac:parameter>\n <ac:parameter ac:name=\"key\">{{issue.key}}</ac:parameter>\n </ac:structured-macro>",
"representation": "storage"}
}
}

You can also add more page content, set page parent, etc. by adding key/value pairs to the json; documentation is in the API reference.

If you want to check whether your setup will work without actually generating pages, you can use the Validate module at the bottom of the setup screen. Just enter a valid ticket number, and the code will run and return a response with expandable entries for response code, payload, etc. This can be helpful in debugging.

automationValidation.png

And that's it! It's a lot of steps, but once you've done it once, you can just copy the rule and change parts as necessary for different projects and requirements.

*The Jira macro that's generated by a page created with the new editor will not display the necessary details when using View Storage Format. If you create a page via automation using the old editor, the link will remain if you later convert the page to the new editor.

7 comments

That goes straight to the bookmarks! 

Really, I would position this one somewhere in my personal top 3 of most useful articles at the community!

Thank you @Esther Strom ! 

Like # people like this

Thanks for this, Esther!

Like Esther Strom likes this

Excellent article! @Esther Strom , Thank you for useful instruction!

Like Esther Strom likes this

Thanks for the article, @Esther Strom This is great information!

I find using the REST API solves several needs which are currently only long-term ideas in the automation backlog, like this one to add Confluence integration: https://codebarrel.atlassian.net/browse/AUT-269

Best regards,

Bill

Like Esther Strom likes this

Thanks @Esther Strom ! This was very detailed and helpful. 

Like Esther Strom likes this

Nice work! Thanks for Sharing!!

Like Esther Strom likes this

Comment

Log in or Sign up to comment
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you