Is there a way I can identify the trigger for the current build during execution. What I want is to identify if the trigger was an SCM change, cron trigger or user trigger. I have multiple triggers defined for a job and want to use trigger type as a parameter in the shell execution script.
4 Answers
You can use the Rest API to get this info; here's an example:
http://jenkins.yourdomain.com/job/job_name/build_number/api/json?tree=actions[causes[shortDescription]]&pretty=true
returns
{
"actions" : [
{
"causes" : [
{
"shortDescription" : "Started by an SCM change"
}
]
},
{
},
{
},
{
},
{
},
{
},
{
}
]
}

- 20,760
- 5
- 52
- 82
One solution is to use the Run Condition Plugin which can run a different shell script depending on the trigger type. It is not the perfect solution, but it will do what you want.

- 996
- 1
- 18
- 32
You can also do it with groovy script. Check out my answer to Jenkins Groovy: What triggered the build you can get the Cause object and then check for which subtype of cause it is http://javadoc.jenkins-ci.org/hudson/model/Cause.html

- 1
- 1

- 2,896
- 2
- 30
- 47
At http(s)://(your-jenkins-server)/jenkins/job/(job-name)/(job-number) , under the "Build Artifacts" and "Changes" sections (if you have them), you should see this icon: . The text next to it should state what caused the build.

- 7,195
- 6
- 41
- 61