In Jenkins, I would like to be able to add multiple users to the watch list of certain job so that these users don't have to go to the job and click watch job by themselves.
import jenkins.model.*;
import hudson.model.*;
import hudson.plugins.emailext.watching.*;
def build = Thread.currentThread().getCurrentExecutable()
def buildEnvVars = new HashMap()
buildEnvVars.putAll(build.getEnvVars())
def JOB_NAME = buildEnvVars["JOB_NAME"]
println JOB_NAME
instance = Jenkins.instance.getItemByFullName(JOB_NAME)
EmailExtWatchAction watch = new EmailExtWatchAction(instance)
User user = User.get("build")
prop = watch.getJobProperty()
prop.addWatcher(user)
instance.save()
println """
IS_WATCHING=${watch.isWatching()}
EMAIL_TRIGGERS=${watch.getTriggers()}
WATCHERS = ${prop.getWatchers()}
"""
In the above code, what I'm trying to do is add user "build" to the watch list of the current job, where the system groovy script is being run. However, nothing is happening. I think it has something to do with the UserProperty. Perhaps I need to add the EmailTrigger to the userProperty?
It would be great if anyone has any insight on this.