Jenkins trigger a job from API

If you are building with parameters then here it is:

Lets say your jenkins build accept two parameters and you want to make the api call using shell script:

You can put following command in shell script:

curl -X POST --data "package_name=ABC.tar.gz" --data "release_notes=none" --data "delay=0sec" https://USERID:TOKEN@JENKINS_URL/job/SOMETHING/SOMETHING/SOMETHING//buildWithParameters

Just use the address bar to make the link. Make sure the link ends with buildWithParameters


The solution is to generate an API token for your Jenkins user (or the Jenkins build user).

Go to the following link for your user:

http://YOUR_JENKINS_URL/user/YOUR_JENKINS_USER_ID/configure

Copy the user_id and token from this section:

enter image description here

And launch the following command to trigger a build:

curl -X POST http://YOUR_JENKINS_USER_ID:YOUR_API_TOKEN@YOUR_JENKINS_URL/job/YOUR_JENKINS_JOB/build

I did a quick test on my https Jenkins server.

Without the token, I got this message:

Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

With the user_id/token, the build is OK with the curl command :)

Tags:

Html

Jenkins