Ever since Automation for Confluence came out, I've been racking my brain trying to figure out what it actually might be useful for. Well, I was inspired by this question about hiding page history. Anyways, here's yet another article that nobody asked for. :-}
Confluence has long had the ability to Share a space externally with anonymous access so that you could "publish" documentation to users/customers outside of your company.
Unfortunately, making a page accessible to anonymous users also makes your Page History and Comments accessible to those same users.
In a traditional CMS (Content Management System), there is usually a mechanism where drafts can be edited, commented on, etc. and then a final "clean" version gets pushed to the public website.
Since Confluence does not allow you to hide comments or page history for anonymously shared spaces, maybe we could instead create a rudimentary CMS system where you have a PRIVATE space that is only accessible to internal users, and a PUBLIC space that is visible to anonymous users
With Automation for Confluence, Atlassian has provided some, but not all of the pieces you might need to hack together such a system.
So we can pretty easily create an Automation Rule that when a PRIVATE page's status changes to "Ready to publish" (a space-specific Suggested Status), it is copied to the PUBLIC space, without any comments or page history:
It's rare that you never need to make changes to a public-facing website. So I went down a rabbit hole of trying to create an Automation Rule that will update existing public pages when changes are made to their corresponding private pages.
When a page is edited, we need to check to see if:
Pretty simple, right? Well, unfortunately it's not.
Well, that does kind of work. Sort of. We now have information on the matching page in the {{cqlResult}} smart value, and we're specifically going to need the page id found in {{cqlResult.id}}
Here's a fun fact - Confluence Automation does not have an "Edit page title" action.
Ok FINE then, Automation does have a Send web request action, and much in the way you can talk to the Jira API from Jira Automation, you can do the same with the Confluence API. (That link has the details on how to get a Personal Access Token that you'll need for the Authorization header.)
We're going to Update content, using an HTTP PUT, but super-annoyingly, before we do that, we have to get the current version number, which, welp, there is NOT a Smart Value for that, so we have to make a separate web request (using HTTP GET) to get that.
In both cases, we are specifying the {{cqlResult.id}} in the URL for the web request (circled in blue).
Note that we are checking the box asking Automation to "Delay execution of subsequent rule actions until we've received a response for this web request". This is important, as we're going to need a value that is returned from this request.
Date returned from web requests is stored in the {{webResponse}} smart value, and in our case, we are looking for {{webResponse.body.version.number}} so that when we update the title of the page, we also increment the version of the page. (This is a required value.)
Because we're using a PUT command, we need to input some Custom data to set the new title (with the date/timestamp), along with the incremented version. Here's what that looks like:
{"title":"{{content.title}} - {{now.jqlDateTime}}",
"type":"page",
"version":{"number":{{webResponse.body.version.number.plus(1)}} },
"space":{"key":"PUBLIC"}
}
When that's all done (remember the "Delay" checkbox in the previous step, because need to finish updating the title of the page before we move on), we Archive the page. No options here. It just does it.
Ok - we've renamed the old PUBLIC page, and we've archived it. We should be good to Copy the page, right? Easy peasy? Oh if only.
Even though its UI makes it looks like the steps in an Automation Rule all run in a straightforward manner, they actually are executed asynchronously. This means that in my case, while I was busy doing having to make web requests (ugh) to find the version of a page and edit the title, Automation tried to COPY the PRIVATE page to PUBLIC before the title changed, and because you can't have pages in the same space with the same title, that failed.
Now, an elegant fix for this would be to NOT try copying the page here, but have a separate rule that is triggered when a page is archived, and allow other rule actions to trigger that rule. Alas, no such trigger exists. (Feature request, please, Atlassian?)
In Jira Automation, we (and by we I mean @Mykenna Cepek and @Bill Sheboy) have a hacky workaround called "Refetch issue data", which forces a reload of all issue data before proceeding, but more importantly delays the execution of the next step in a rule. We effectively use it as a sleep() function, but it's not ideal, and oh look there is no equivalent solution in Confluence.
SO, I started thinking if I'm going to do ugly stuff with web requests, there's probably a website where I can just request a delay. So I make a request for a 3 second delay here:
https://hub.dummyapis.com/delay?seconds=3
And then I copy the page. Super janky, but it works.
Darryl Lee
Sr. Systems Engineer
Roku, Inc.
San Jose, CA
184 accepted answers
6 comments