Hi all.
I understand user can go to a job and click watch job to subscribe yourself for the changes of this job. What I'm trying to do is in system groovy, use the class in Jenkins email-ext plugin to add other people to the watch job list.
At the moment, after I run my script, user "build" is not added to the watch list.
Here's my system groovy script:
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()}
"""
Many thanks,
Kevin