0

using below typescript function to trigger a jenkins build -

  httpOptions = {
    headers: new HttpHeaders({
   'Content-Type':  'application/json',
   'Authorization': 'Basic ' + btoa('username:password'),
   })
  };
triggerJenkinsJob(productname:string):Observable<any>{
   console.log("service called")
   var url = "http://jenkinsbox:30000/job/demo/buildWithParameters?project_name=demo"
   return this.http.post(url,this.httpOptions)
   .pipe(map(function(item){
     console.log(item)
   }))
 }

with the above code, nothing is executing on the jenkins box. I have tried running the below URL on the browser, which is working perfectly.

http://jenkinsbox:30000/job/demo/buildWithParameters?project_name=demo

Suraj Nerati
  • 99
  • 1
  • 8

1 Answers1

0

If your question is why triggerJenkinsJob('demo').subscribe() does not as intended, you should read logs in your browser's console.

The first problem should be CORS. You may have a second problem with CSRF protection if there is one with Jenkins

HTN
  • 3,388
  • 1
  • 8
  • 18
  • I have installed CORS Support plugin and added the origin,headers over there. fyi, I have already consuming the /api/json. get request is already working. CSRF protection - I have also tried passing Jenkins-Crumb with headers as well. – Suraj Nerati Apr 04 '19 at 08:39
  • What is the status / error of the POST request in the browser's developer tool console / network? – HTN Apr 05 '19 at 07:12