title: Build Jenkins job with parameters from CURL / HTTP POST
body: <p>I am making an AJAX request to invoke a <code>PHP(preferably) or similar</code> file and want that code to <code>trigger jenkins job remotely</code>. Also I would like to pass <code>parameters</code> to the job that will get triggered. For example, along with AJAX request, my <code>data</code> will be holding the value of some vars such as <code>job</code> name, <code>runid</code>, etc. as shown below:</p>
  
  <pre><code>$.ajax({
        url: 'runjob.php',
        type: "GET",
        data: { job : job, runid : id },
        success: function(data) {
  ....
  }
  </code></pre>
  
  <p>As per <a href="https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API" rel="nofollow">https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API</a>, I have written a small PHP code below:</p>
  
  <p><strong><em>runjob.php</em></strong></p>
  
  <pre><code> &lt;?php
  
  curl -X POST http://mobile-jenkins.testzynx.com:8080/job/trserver-git/build \
    --data token=12981209380192380129802 \
    --data-urlencode json='{"parameter": [{"name":"id","value":runid}, {"name":"profile", "value":"tr-flex.properties"}]}'
  
  ?&gt;
  </code></pre>
  
  <p>where <code>runid</code> is the var that I will have in my AJAX request code and <code>trserver-git</code> is the name of jenkins job.</p>
  
  <p>which follows the syntax as shown in the actual URL:</p>
  
  <p><strong><em>syntax from above url</em></strong>
      
  
  <pre><code>curl -X POST JENKINS_URL/job/JOB_NAME/build \
    --data token=TOKEN \
    --data-urlencode json='{"parameter": [{"name":"id", "value":"123"}, {"name":"verbosity", "value":"high"}]}'
  
  ?&gt;
  </code></pre>
  
  <p>where token is the user API token that I got from my properties in Jenkins.</p>
  
  <p>However, this code(<code>runjob.php</code>) does not seem to work and <code>I am not able to trigger jobs and hence no parameters</code>. </p>
  
  <p>Later once I am able to trigger the job with parameters passed, <code>I want to read those parameters to a shell scipt that runs as a part of jenkins job.</code> For example,</p>
  
  <p><code>./runTest.sh -Drunid=$id -Dprofile=$profile</code> like maven parameters.</p>
  
  <p>Is there a good example on how to achieve this remote parameterized jenkins job trigger and read parameters scenario? <code>PHP preferred</code>.</p>