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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Change labels with Groovy script


I want to run a groovy script when a button is clicked which changes the label.

We have three labels for page classification.

- Internal

- Confidential

- Public


I don't want that users need to change them manually. With Scriptrunner for Confluence I was easily able to create buttons in the action menu.

But I can't find an example script for Confluence.

The script should:

- Remove the existing classification label

- Add the new label

- Not change other existing labels


I found something similiar for Jira.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels({it.getLabel()}
labels -= 'labelToBeRemoved'

By adding labels +='label' I believe I could add the new label


Can someone help? :)

2 answers

I'm interested in the answer of this as well. I am trying to add a label to a dynamically created page. I followed Florian's suggestion and looked at the Confluence LabelManager class here

Unfortunately, when I add the following import line in my script:

import com.atlassian.confluence.label

It doesn't seem to recognize this. I am running version Confluence Server 6.13.11. How can I tell if this is available?

BTW, I tried this import inside IntelliJ and it was able to find it without a problem. So that confirms that the class exists (obviously).

Hey :)

there you should find all the available classes for your instance.

Form these docs:


Class Label

  • java.lang.Object
    • com.atlassian.core.bean.EntityObject
      • com.atlassian.confluence.labels.Label

But your issue probably comes from your import which is not correct:

// wrong
import com.atlassian.confluence.label

import com.atlassian.confluence.labels.Label



Hope that can help you :) 

Hey Magnus,

we needed to add Labels to an existing page. And used this code:

import com.atlassian.confluence.pages.Page
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.labels.LabelManager

Page addLabelsToPage(List<Label> labels, Page page) {
labels.each { Label label ->

Looks like there is a LabelManager in Confluence too ;)
Confluence Docs - LabelManager  


Hope that will help you with your Problem.

Greetings From Germany 


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events