Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Data centre icon
Data Center

Add Label to Outdated Pages Job

Features
Jobs
Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence (7.15 - 8.6)
compatibility bullet
ScriptRunner For Confluence (7.10.0)
Language |
groovy
package examples

import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.labels.LabelManager
import com.atlassian.sal.api.component.ComponentLocator
import static com.atlassian.confluence.labels.Namespace.GLOBAL
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput

@ShortTextInput(label = 'Label', description = 'Label to add to pages')
String labelName
assert labelName

def labelManager = ComponentLocator.getComponent(LabelManager)
def label = labelManager.getLabel(labelName) ?: labelManager.createLabel(new Label(labelName, GLOBAL))
hits.each { page ->
    if (!page.labels*.name.contains(labelName)) {
        labelManager.addLabel(page, label)
    }
}
Having an issue with this script?
Report it here