how to trigger jenkins job via curl command remotely

I have tried to execute(trigger) jenkins job (not a parameterized job) via curl command by using below methods but it showing these results. my jenkins version is Jenkins 2.73.3

curl -X POST -u jenkins_user_name:jenkins_user_passwd http://jenkins_server/job/job_name/build

But it says Forbidden 403 enter image description here

Therefore, I have created a Authentication Token for the Job enter image description here

curl -X POST http://jenkins_server/job/job_name/build?token=wefiytgwiefiweihfqweiodf

It's also giving the same error. it says Forbidden 403

After that , I have created an API Token for jenkins User and tried. enter image description here

curl -X POST -u auto:testingdae6dc22a73048e6d596e7b0 http://jenkins_server/job/job_name/build?token=wefiytgwiefiweihfqweiodf

But It also the same , it says Forbidden 403

Actually I have followed this answer as well. https://www.nczonline.net/blog/2015/10/triggering-jenkins-builds-by-url/ this is also not worked for me.

every time , It's 403 forbidden. I think I couldn't authenticate jenkins user properly.


found the answer. Actually those steps are correct. I would like to mention the correct steps.

Create a user in Jenkins, you can use that user password or API token for trigger Jenkins job. But creating an API token for that user is much better. But both ways working fine.

But you have to create an Authentication token for Jenkins Job

enter image description here

Using Password

curl -I -u auto:<userpasswd> http://<jenkins_server>/job/test/build?token=wefiytgwiefiweihfqweiodf

Using an API Token

Create an API token for that Jenkins user enter image description here

curl -I -u auto:<user_api_token> http://<jenkins_Server>/job/test/build?token=wefiytgwiefiweihfqweiodf

these are the results, using jenkins user Password and jenkins user API token.

enter image description here

Actually you can send this request , without "-I" as well.

curl -u auto:<jenkins_user_token> http://<jenkins_server>/job/test/build?token=wefiytgwiefiweihfqweiodf

curl -u auto:<jenkins_user_password> http://<jenkins_server>/job/test/build?token=wefiytgwiefiweihfqweiodf

To configure these permissions:

  • Click Manage Jenkins
  • Click Configure Global Security
  • Remove Prevent Cross Site Request Forgery exploits
  • Click save