53
votes

I am new to Jenkins, and I'm not sure if this is possible, but I would like to set up a web interface where somebody could click "Start Job" and this will tell Jenkins to start a particular build job.

Does Jenkins have a webservice that would allow such a thing? If so, what would be a simple example?

10
Did you able to resolve this??, i've to do the same thing, can you please let me know how you sorted this any sample code or links.. - Sam
Yes, it's actually straight-forward. Just like the selected answer says, you call a URL in the form JENKINS_URL/job/JOBNAME/build?token=TOKEN You set the token when setting up job. - chaimp
how do i pass the parameter such as mvn command line arugments.. - Sam
You make parameters in your job, and then you should be able name them in the URL string - chaimp
You could always integrate with another tool, BuildMaster has a Queue a Jenkins Build operation you can use as part of a deployment plan. - Karl Harnagy

10 Answers

59
votes

Here is a link to the documentation: Jenkins Remote Access API.

Check out the Submitting jobs section.

In your job configuration you setup a token and then create a POST request to JENKINS_URL/job/JOBNAME/build?token=TOKEN. That's probably the most basic usage.

30
votes

Jenkins has support for parameterized build as well.

So, if you want to pass parameters for configurable build generation, you can pass them by posting it while invoking Jenkins build request with http://YOURHOST/jenkins/job/PROJECTNAME/buildWithParameters.

8
votes

Aha, I found it in the documentation. So simple:

http://YOURHOST/jenkins/job/PROJECTNAME/build
5
votes

I needed to add parameters and I wanted to do it over https. It took me a while but the following worked for me:

curl --request POST --url 'https://HOST_NAME/job/JOB_NAME/buildWithParameters?token=TOKEN'  --header 'cache-control: no-cache' --header 'content-type: application/x-www-form-urlencoded' --data 'name1=value1&name2=value2'
5
votes

Use:

http://some server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value

You can take a look at this documentation: Parameterized Build

4
votes

There is a good sample of using the above API from Python. The project is called Python Jenkins, and you may find it here: link

3
votes

Jenkins has a documented REST API. You can make your little web service invoke it.

3
votes
curl -H POST http://USERNAME:PASSWORD@JENKINS_HOST:PORT/job/JOB_NAME/build?token=YOUR_TOKEN

Set YOUR_TOKEN at job configuration -> build triggers -> Trigger builds remotely.

2
votes

With curl if you have multiple arguments to pass like a token and a parameter you might have to quote on Linux shell:

curl -H POST "http://USERNAME:PASSWORD@JENKINS_HOST:PORT/job/JOB_NAME/build?token=YOUR_TOKEN&PARAMETER=VALUE"
0
votes

Install Generic Webhook Trigger plugin. Select generic webhook trigger in build trigger actions. Generate a random string and paste in token. Now your job can be triggered with a http request to the following url.

screenshot

http://JENKINS_URL/generic-webhook-trigger/invoke?token=TOKEN_VALUE

replace your jenkins url and token value