Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

CMS with Confluence Automation?! Sure why not?

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. :-}

giphy

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. 

Publish PRIVATE page to PUBLIC space

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:

Screenshot 2023-06-06 at 11.35.25 PM.png

Notes:

  • We have to make this a Global rule and use the CQL condition to check if the "published" page was in the PRIVATE space because we are going to Copy the page into a different space.
  • This system does not preserve page order (the newest page will always be at the end), and it cannot deal with nested pages.*

Edit published PRIVATE page, update corresponding PUBLIC page

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:

  • It is in the PRIVATE space
  • 1) Whether it was already published OR 2) if there is already a page in the PUBLIC space with the same title.
  • If so, add a date and timestamp to the title of the page (because even when a page is archived, it prevents any other pages in the space from having the same title).
  • Archive the page.
  • Copy the edited PRIVATE page to the PUBLIC space.

Pretty simple, right? Well, unfortunately it's not. 

  1. Atlassian unintentionally left a smart values lying around that would have helped with checking if a page previously in the "Ready to publish" state: {{content.previousContentState.name}}

    But shortly after I found it, they took it away. Boo. (Oh hi @Trev Angle - I have some more feature requests and a bug at the end of this article.)
  2. Ok then, surely it should be possible to check if a page with a certain title exists in space, right? You would think maybe a CQL condition would do the trick, but oops, that only works for the page that triggered the automation. We want to do a "lookup" of a completely different page.

    Well, what if used a Branch rule / related entities to do a query like:

    space = PUBLIC and title = "{{content.title}}"


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}} 

Edit the title of the page

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).

GET page information, including the version

Screenshot 2023-06-06 at 11.35.37 PM.png

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.)

PUT update to the Title and Version of the page Screenshot 2023-06-06 at 11.35.49 PM.png

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"}
}

Archive old PUBLIC page

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.

Copy edited PRIVATE page to PUBLIC

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

Screenshot 2023-06-06 at 11.35.58 PM.png

And then I copy the page. Super janky, but it works.

Annoyances it would be nice if Atlassian could fix:

Feature Requests

  • * If Atlassian were to allow us to put smart values (like {{page.parent.title}}) into the "Parent page" field when Copying a page, we could have nested pages, maybe.
  • It's silly (and a lot of work) to have to use the API to change the title of a page. This should be an action.
  • Page archived trigger.
  • Delay/sleep action (JIRAAUTOSERVER-23)

Bug

  • Page status changed trigger fires when status of an edited page matches the target status, not if it changed to the target (which is what "page status changed" means to me). This bug results in my first rule trying to fire after every PRIVATE page edit. So far that means it tries to copy the page, but fails because it has (not yet) been renamed by the other rule.

    I even tried to find a workaround to this by making a web request to do a CQL search for a PUBLIC pages with the same title as in PRIVATE, and check if the size is 0, but super-annoyingly {{webResponse.body.size}} always returns 1 (probably because it's named the same as the size function).

    (My query: https://MYSITE.atlassian.net/wiki/rest/api/content/search?cql=space=PUBLIC%20AND%20title=%22this%20is%20a%20page%22)

6 comments

Amelie Winkler _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 7, 2023

Oh, nice one @Darryl Lee! Your "articles no one asked for" are always an inspiration

Like # people like this
Patricia Ermisch [Catworkx]
Contributor
June 7, 2023

@Darryl Leeyou are a genius, thank you for the very helpful article. 👍👍

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2023

Elsewhere @Russell Stadler asked:

For the web requests, whose token ends up saved in there?  I have always felt nervous about putting a personal token into one of these rules but maybe that's misplaced.

Oooh, that's a great point.
Best practice would probably be to create a service account and use that, although you end up burning a license.
But since we're using the API to change page titles (which shows up in Page history), and since the Archived pages UI shows who archived a page, it'd probably be very helpful to have a "CMS Agent" user that the rule can run as, and so yeah, using that same user's token makes sense as well.
Like # people like this
jamie_slater June 7, 2023

awesome!

Avinoam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2023

@Darryl Lee this post is just 😍! Thank you so much for even adding such an organized list of feature requests :)

By way of quick intro, I'm the new Confluence Automation PM and I'd love to get a chance to speak with you. If you'd be interested, please feel free to book time directly with me (and the team) here.

Hoping to chat more soon!

Avinoam

Like # people like this
Nidhi Raj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2023

@darryl Thank you for engaging so actively with our products and community! 

We also have the Confluence Public Links feature coming up for general availability in just a few months, which allows you to generate a unique public URL for a Confluence page, for anyone on the internet with the link to see a view-only version of the page. This hides the page comments and history, along with some other elements of a traditional Confluence page. Read the support article for details!

Like Andy Gladstone likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events