2

How can I remotely trigger a Jenkins job with the help of an R code?

When I post this URL in my browser it works-

https://JENKINSURL/job/PROJECT/buildWithParameters?token=TOKEN&day=20171001

Not sure how to replicate this with my R code. I used the POST function in HTTR call but I always get an HTTP 403 error.

res <- POST("https://JENKINSURL/job/PROJECT/buildWithParameters?token=TOKEN&day=20171001",verbose())

Authentication required

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

Any thoughts on what I may be doing wrong?

Arpit Solanki
  • 113
  • 1
  • 6

1 Answers1

1

You aren't specifying a user ID in your request, so it is going to be using the anonymous user. Your anonymous user has to have read access to the job (or job->read in global perms) you are trying to trigger, or it won't be authorized to access the job/PROJECT uri to trigger the build.

So you have to either specify a user ID with the proper read access in the url, give the anonymous user read access, use project-based matrix auth, or you can use the Build Token Root plugin to provide a different URL that doesn't require read access to the job. Then you only need the token.

Rob Hales
  • 4,330
  • 1
  • 15
  • 29
  • How would the structure of my URL look like if I provide the User ID in the request? – Arpit Solanki Oct 16 '17 at 02:06
  • https ://user:apitoken@JENKINSURL/job/PROJECT/buildWithParameters?token=TOKEN&day=20171001 ignore the space after https. Just didn't want it to convert to a URL in the comments. – Rob Hales Oct 16 '17 at 02:25
  • I tried the above page but it just prints a long HTML page in the console and does not trigger the job. – Arpit Solanki Oct 16 '17 at 05:13
  • Try it in a browser and see what the message is. It will probably clue you into the problem. – Rob Hales Oct 16 '17 at 05:31
  • It redirects me to the sign in page for Jenkins when I paste it in the incognito mode in browser. Maybe there is some issue with the authentication. – Arpit Solanki Oct 16 '17 at 06:29