create new job using jenkins API with AJAX

10 views
Skip to first unread message

Richard Zilahi

unread,
May 29, 2017, 12:11:41 PM5/29/17
to Jenkins Users
I am trying to create a new job by triggering the jenkins' createItem endpoint, using the following code: 

$(document).ready(function() {
      $
("#create").click(function (e) {
        e
.preventDefault();
       
var newJobName = $("#jobname").val();
       
//console.log(newJobName);
        jQuery
.ajax({
            type
: "POST",
            url
: "http://robot:<api1>@host/jenkins/createItem?name="+newJobName,
            dataType
:"xml",
            contentType
: "application/xml",
            success
:function(response){
                console
.log("success");
           
},
            error
:function (xhr, ajaxOptions, thrownError){
                alert
(thrownError);
           
}
       
});
     
});
   
});

But i am getting 500 server error. I know I should post the
config.xml

file also but i don't really know how to extend this code to be able to post the file also. 

I am using a self-written client to interact with jenkins and the API is works well for build triggering. 

Any help would be really appreciated!
Reply all
Reply to author
Forward
0 new messages