how to detect wheather job started by upstream project or user has manually started project using groovy

1,239 views
Skip to first unread message

niraj nandane

unread,
Oct 14, 2014, 7:27:00 AM10/14/14
to jenkins...@googlegroups.com
I have one job which i start as a downstream job. I want a groovy script which will detect wheather this job is started as a downstream job or user has started it customly by clicking build now button.
Based on that i want to execute another job say "abc" .Means if current job started as downstream job then do not execute "abc" otherwise execute "abc" and wait until it finish
--
Thanks and regards--
Niraj Nandane(Vit pune)

Shawn Speer

unread,
Oct 17, 2014, 3:40:07 PM10/17/14
to jenkins...@googlegroups.com
There may be an easier way, but you can load the build.environment and evaluate the 'BUILD_CAUSE_UPSTREAMTRIGGER' environment variables to determine this.  The value is boolean.  There is also a 'BUILD_CAUSE' environment variable with values of 'MANUALTRIGGER', 'TIMERTRIGGER' and 'UPSTREAMTRIGGER'.  There are probably more values, but that is what I see for my jobs. 

For a groovy template, this would be:

def env = build.environment
def cause = env.BUILD_CAUSE_UPSTREAMTRIGGER

Assume the same for a script.  If you want to find out the user information in the event of a manual trigger, you can install the Build User Vars plugin.
Reply all
Reply to author
Forward
0 new messages