Issues running a Jenkins job with parameters via jquery/ajax - api

20 views
Skip to first unread message

Cliff Hanger

unread,
Jun 26, 2019, 1:07:37 AM6/26/19
to Jenkins Users
Hi,

I have the below code, somehow I just cant seem to pass the parameters to Jenkins:


   var parameters = '{"parameter": [{"name":"id", "value": "2"}, {"name":"id2", "value": "testing"}]}';
   $.ajax({
        url: "https://abc/job/test/buildWithParameters",
        beforeSend: function(xhr) {
            xhr.withCredentials = true;
            xhr.setRequestHeader('cache-control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
            xhr.setRequestHeader("Authorization", "Basic " + btoa("abc:*******"));
        },
        type: "POST",
        dataType: "jsonp",
        contentType: "application/json; charset=utf-8",
        cache: false,
        async: false,
        processData: false,
        data: 'json='+parameters,
        success: function (data) {
            alert(JSON.stringify(data));
    },
    error: function(){
        alert("Cannot get data");
    }
});


Can someone please help me with what am I doing wrong? Also it always goes in the error function and not in the success, why is that the case?

--Ishan

Cliff Hanger

unread,
Jun 27, 2019, 4:15:42 PM6/27/19
to Jenkins Users
Any suggestions??
Reply all
Reply to author
Forward
0 new messages