How to determine whether the Jenkins build was started by a user or the scheduler? I have a Jenkins job which does some unit-testing for some code. It can be started in two possible ways:

By the scheduler - it polls the Perforce server, and starts the job when it detects a code change
By a user, on demand - it downloads a shelved/stashed code change, and checks whether it breaks the tests

The second way is called &quot;Build Review&quot;:


If the job discovers problems, I want to send emails conditionally, to avoid spam:

If invoked by the scheduler, send mails to everyone who did check-ins since last successful build (called &quot;developers&quot; in Jenkins jargon)
If invoked by a specific user, send a mail only to that user

I am using the Any Build Step plugin to add two conditional instances of Editable email Notification into my job settings. But what are the conditions? How can I tell it to send mail only if invoked in a specific way, (1) or (2) above?
I'm not sure if there is a simple way to check if the &quot;scheduler&quot; kicked off the job, but you can check if a user executed the job.
In your Jenkins job, check for the presence of the BUILD_USER_ID environment variable. If it is present, retrieve the value and send your email to the specific user(s) (scenario 1). If it is not present, a non-user has executed the job, and you can email the users listed on the last successful check-in (scenario 2).
If you are looking for methods outside of the Jenkins job, you can also use the Jenkins API (http://jenkinsurl/job/[JobName]/[BuildNumber]/api/json?pretty=true) and parse the BUILD_USER_ID from the output.