Jenkins email ext - How to add other people to watch job list

25 views
Skip to first unread message

Kevin Yu

unread,
Oct 7, 2016, 1:42:59 PM10/7/16
to jenkins...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages