Stand with Ukraine 🇺🇦

Page Fixed Version — Confluence Cloud Macro

admin

This Confluence user macro displays a page’s fixed version by scanning for labels starting with fixed-version_. It uses the Confluence Cloud REST API to check the labels of the current page and its parent pages (up to the space homepage), allowing version values to be set once and reused across related documents. This makes it easy to keep release information consistent across multiple pages.

Try for free

Template

#set($fixVersion = "")
#set($pageIdToCheck = $page.id)

#foreach ($i in [1..50])  ## Set a safety limit to prevent infinite loops
  #if ($pageIdToCheck)
    #set($labelResponse = $ConfluenceManager.get("/wiki/api/v2/pages/$pageIdToCheck/labels"))

    #if ($labelResponse && $labelResponse.results)
      #foreach ($label in $labelResponse.results)
        ## Look for label starting with e.g. "fixed-version_450"
        #if ($label.prefix == "global" && $label.name.startsWith("fixed-version_"))
          ## $fixVersion = 450
          #set($fixVersion = $label.name.substring(14))
          #break
        #end
      #end
    #end

    #if ($fixVersion != "")
      #break
    #end

    #if ($pageIdToCheck == $space.homepageId)
      #stop
    #end

    #set($pageInfo = $ConfluenceManager.get("/wiki/api/v2/pages/$pageIdToCheck"))
    #if ($pageInfo && $pageInfo.parentId)
      #set($pageIdToCheck = $pageInfo.parentId)
    #else
      #break
    #end
  #end
#end

#if ($fixVersion != "")
    $fixVersion
#else
  <span style="color: #888;">
    No fixed version found. Label this page or one of its parents with 
    <code>fixed-version_x.y.z</code>.
  </span>
#end