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.
Here's where the fun starts. You'll need to enter the following information:
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.
You'll see a page that looks like this:
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.
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.
Esther Strom
Associate Manager, IT Administration
Pizza Hut US
Chicago
77 accepted answers
30 comments