Jenkins: determine the type of trigger

Is there a way to define a trigger for the current assembly at run time. I want to determine if a trigger was an SCM change, a cron trigger, or a user trigger. I have several triggers defined for the job, and you want to use the trigger type as a parameter in the execution of the shell script.

+4
source share
3 answers

You can use the Rest API to get this information; here is an example:

http://jenkins.yourdomain.com/job/job_name/build_number/api/json?tree=actions [calls [SHORTDESCRIPTION]] & pretty = true

returns

{
  "actions" : [
    {
      "causes" : [
        {
          "shortDescription" : "Started by an SCM change"
        }
      ]
    },
    {

    },
    {

    },
    {

    },
    {

    },
    {

    },
    {

    }
  ]
}
+1
source

, script . , , .

0

You can also do this with a groovy script. See my answer to Jenkins Groovy: what caused the assembly you can get the Cause object and then check which subtype of the reason is http://javadoc.jenkins-ci.org/hudson/model/Cause.html

0
source

All Articles