Calling a Jenkins build from outside of Jenkins?

Jenkins

Jenkins Problem Overview


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?

Jenkins Solutions


Solution 1 - Jenkins

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.

Solution 2 - Jenkins

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.

Solution 3 - Jenkins

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

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

Solution 4 - Jenkins

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'

Solution 5 - Jenkins

Use:

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

You can take a look at this documentation: Parameterized Build

Solution 6 - Jenkins

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.

Solution 7 - Jenkins

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

Solution 8 - Jenkins

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

Solution 9 - Jenkins

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"

Solution 10 - Jenkins

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchaimpView Question on Stackoverflow
Solution 1 - JenkinsmikelView Answer on Stackoverflow
Solution 2 - JenkinsApurvView Answer on Stackoverflow
Solution 3 - JenkinschaimpView Answer on Stackoverflow
Solution 4 - JenkinsSamuel GarrattView Answer on Stackoverflow
Solution 5 - JenkinskazermView Answer on Stackoverflow
Solution 6 - JenkinsAmr LotfyView Answer on Stackoverflow
Solution 7 - JenkinsvladisldView Answer on Stackoverflow
Solution 8 - JenkinsbmarguliesView Answer on Stackoverflow
Solution 9 - Jenkinsstack_lechView Answer on Stackoverflow
Solution 10 - JenkinsYogesh SagarView Answer on Stackoverflow