Example scripts
To homepage
Confluence

Add Labels To Spaces In Bulk
App in script

ScriptRunner For Confluence
by Adaptavist
Compatibility

Confluence (7.15 - 8.6)

ScriptRunner For Confluence (7.10.0)
Language |
groovy
import com.atlassian.confluence.labels.SpaceLabelManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.spaces.Space
import com.onresolve.scriptrunner.parameters.annotation.SpacePicker
@SpacePicker(label = 'Spaces', description = 'Select the spaces to apply labels to', multiple = true)
List<Space> spaces
assert spaces
//Edit the Label names to meet your need
def labelNames = ['label1', 'label2']
SpaceLabelManager spaceLabelManager = ComponentLocator.getComponent(SpaceLabelManager)
def errors = [] as Set
spaces.each { space ->
labelNames.each { labelName ->
try {
spaceLabelManager.addLabel(space, labelName)
} catch (IllegalArgumentException e) {
errors.add(e.message)
}
}
}
if (errors.size() == 0) {
log.info("All labels listed have been added to the selected spaces.")
} else {
log.error("All labels listed have been added to the selected spaces except the following error(s).")
errors.each { log.error(it) }
}
Having an issue with this script?
Report it here