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
In my case i had the URL and token correct, but had forgotten one of the required permissions for the API user that triggers the URL/build.
The permissions have to minimally include the list here:
I also have faced the same issue and resolved it.
Consider, you have 2 Jenkins A and B. If you want to execute a build job present in Jenkins B, then you have to give the API token of Jenkins B. If you provide the API token of Jenkins A, it will show the authentication issue only.
This is the mistake I have did and it got resolved once I have changed the API token properly according to the required Jenkins.
Install Parameterized Build plugin
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
If you are using an authorization token to trigger the builds (Job -> Configure -> 'Build Triggers' -> 'Trigger builds remotely (e.g., from scripts)'), you can access:
curl -X POST http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value
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.
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-
This works for me:
tokenuser = You need login with the user and check token config jenkins -> admin users
user = username
curl -XPOST --silent --show-error --user user:tokenuser "http://ipserver/jenkins/buildByToken/build?job=JOBNAME&token=7RJWiIwD5cW3S6QjwF7a"
Example:
curl -XPOST --silent --show-error --user desarrollador:b9611288e4159ea9fb7857faeadd06fe "http://ipserver/jenkins/buildByToken/build?job=DeployGF&token=7RJWiIwD5cW3S6QjwF7a"