Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Remote Trigger Not Working

Tags:

curl

jenkins

I am getting the following error when i try triggering a build using the following command:

curl http://jenkins_server:port/jenkins/job/job_name/build?token=token_name

Output:

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
->

I have admin rights and have also enabled 'Authentication Token'. I also have Build, Discover and Read rights on Job. I am using Jenkins 1.614.

I did check several posts online but could not find anything that works for me.

Tried few options such as
1) curl -X POST http://jenkins_server:port/jenkins/job/job_name/build?token=token_name
2) curl -u user:API (Prints a long HTML page)

Any suggestions.

like image 273
Technext Avatar asked Jul 14 '15 14:07

Technext


People also ask

How do I trigger a Jenkins job in remote Jenkins?

Create a remote Jenkins build trigger in three stepsCreate a Jenkins build job and enable the Trigger builds remotely checkbox. Provide an authentication token; This can be any text string of your choice. Invoke the Jenkins build URL to remotely trigger the build job.

Which command is used to trigger build remotely in Jenkins?

In the new Jenkins Pipeline, under Build Triggers, select the checkbox Trigger builds remotely (e.g., from scripts). Then give Jenkins a token that will be required when triggering the build.

How do you trigger Jenkins job from another Jenkins job?

Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option. This configuration allows you to trigger another exciting job on a different CM (remote). The downstream job name part will autocomplete.


2 Answers

I install Build Token Root Plugin to solve this issue before

https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

Then as the same, setup Authentication Token

Finally, either use curl to trigger remote build (Be careful the escape character "\")

curl http://JENKINS_URL/buildByToken/build?job=JOB_NAME\&token=TOKEN_NAME

or paste the URL to your browser (No needs escape character "\")

http://JENKINS_URL/buildByToken/build?job=JOB_NAME&token=TOKEN_NAME

If you see Succeed, it means that trigger remote Jenkins successfully.

Note that, you don't have to setup build, discover, and read rights on Job

For more information, you could reference to https://cloudbees.zendesk.com/hc/en-us/articles/204338790-Why-are-builds-not-being-triggered-with-Build-Token-Root-Plugin-

like image 78
hsiaoairplane Avatar answered Oct 21 '22 01:10

hsiaoairplane


I think there's no need to set up any kind of plugin to make it works, simply do this BATCH CMD:

curl -X POST http://USER_ID_JENKINS_RECEIVER:TOKEN_OF_USER_ID_JENKINS_RECEIVER@URL_JENKINS_RECEIVER:PORT/job/NAME_OF_JOB/buildWithParameters?token=TOKEN_JOB_JENKINS_RECEIVER
  • To see you USER_ID_TOKEN, go to your username at the top-right of jenkins > go to Configure > Click on API Token and it will be displayed.

  • You must configure a token on the JOB_OF_JENKINS_RECEIVER

I have to say that it works perfectly on Jenkins without any kind of permissions to anonymous users.

like image 16
M. Mariscal Avatar answered Oct 21 '22 03:10

M. Mariscal