6

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.

dOps
  • 730
  • 2
  • 7
  • 16

4 Answers4

2

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"
        }
      ]
    },
    {

    },
    {

    },
    {

    },
    {

    },
    {

    },
    {

    }
  ]
}
gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
1

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.

Illidanek
  • 996
  • 1
  • 18
  • 32
0

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

Community
  • 1
  • 1
Tidhar Klein Orbach
  • 2,896
  • 2
  • 30
  • 47
0

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: An orange diamond with gears . The text next to it should state what caused the build.

cowlinator
  • 7,195
  • 6
  • 41
  • 61