Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: identify trigger type

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.

like image 917
dOps Avatar asked Oct 01 '13 08:10

dOps


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

    },
    {

    },
    {

    },
    {

    },
    {

    },
    {

    }
  ]
}
like image 104
gareth_bowles Avatar answered Nov 15 '22 06:11

gareth_bowles


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.

like image 42
Illidanek Avatar answered Nov 15 '22 05:11

Illidanek