Skip to content

Instantly share code, notes, and snippets.

@mfoti
Last active August 29, 2015 14:22
Show Gist options
  • Save mfoti/ae17d59acb2700cdd785 to your computer and use it in GitHub Desktop.
Save mfoti/ae17d59acb2700cdd785 to your computer and use it in GitHub Desktop.
This is a working solution to add JIRA Watcher with a ScriptRunner Listener
//put this in <jira-home>/AddJiraWatcherListener.groovy and activate through custom listener
Import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
class AddJiraWatcherListener extends AbstractIssueEventListener {
@Override
void workflowEvent(IssueEvent event) {
def componentManager = ComponentManager.getInstance()
def watcherManager = componentManager.getWatcherManager()
def userManager = componentManager.getUserUtil()
def watchUsers = {usernames ->
usernames.each {
def user = userManager.getUser(it)
watcherManager.startWatching(user, event.issue.getGenericValue())
}
}
def users = ["skler", "username2", "username3"]
watchUsers(users)
//log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by ExampleListener"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment