Jenkins API Integration : Trigger Job Remotely via Jenkins API

04 / Nov / 2015 by Aditya Thakur 3 comments

Jenkins provide continuous integration to software development. Jenkins job builds can be started by various methods, like manual triggering, scheduled cron-like mechanism, dependency builds, and by Jenkins API calls.

This blog will cover Jenkins API Integration : Trigger Job Remotely via Jenkins API.

1.  First, we need Jenkins API TOKEN which will be ‘configure’ tab on Jenkins.


2.  Generate the URL for Jenkins Job.

Go to Jenkins website and add “api/json” to any page. If we get a JSON response on the browser, then that page can be accessed remotely. For converting it to readable format, use “api/json?pretty=true”


For example :


3. Make ‘HTTP POST’ request to Jenkins server.

NOTE: Jenkins only supports ‘HTTP POST’ request for remote requests.

‘HTTP POST’ request can be of two types.

(A) Without parameters : 

URL FORMAT -> jenkins_url/job/job_name/build?token=TOKEN.

For example :

(B) Parameterized :

URL FORMAT -> jenkins_url/job/job_name/buildWithParameters?token=TOKEN&parameter=VALUE

For Example :

After this, we also need to add {key:value} pair authorization to the ‘HTTP POST’ request. It will be in format
{auth: “jenkins_user_email:jenkins_user_password”}.

Final request will look like..

Curl Request : 

curl -v -X POST jenkins_url/job/job_name/buildWithParameters
--data token=your_token
--user jenkins_user_email:jenkins_user_password
--data-urlencode json= '{"parameter1":"value1", "parameter2":"value2"}'

Finally, we will get the response of ‘HTTP POST’ request with property ‘statusCode’ (201 for success, else for errors)


We have successfully triggered Jenkins job remotely. You may want to check it on Jenkins now.
We also track the Job Status and Console remotely using Jenkins API which will be covered in my next blog.
Stay tuned. :)


comments (3)

  1. Shan

    thanks, it is working :)… Is it possible to display the authenticated username, who triggered the job? Currently it is just displaying “started by remote host 90.XX.XX.XX”

  2. Gopalakrishnan

    Can I access the parameter and values inside the build-job for a job triggered in this fashion using REST API ?would you have any examples ?

    1. Aditya ThakurAditya Thakur

      Yes, you should be able to do that, I don’t have any example ready but if you are interested I can look for something.


Leave a comment -