I'm using Jenkins ver. 1.406 and can't get to trigger a parametrized (3 strings) build using AJAX.
Some docs talk about a "token" but there is no such option in Jenkin's OR job's configuration panels.
I'm sending the ajax call like this:
var jqxhr = $.post(
"http://servername:8080/job/jab-name/build/api/json",
{ "parameters": [{ "PARAM1": "value1" }, { "PARAM2": "value2" }] },
"js开发者_运维百科on"
)
.success(function () { alert("success"); })
.error(function (xhr, ajaxOptions, thrownError) { alert("Error\nxhr.status = [" + xhr.status + "]\n xhr.status: [" + xhr.statusText + "]\najaxOptions = [" + ajaxOptions + "]"); })
.complete(function () { alert("complete"); });
Parameters are correct (case sensitive) and all of them are set, not use of default value(s).
Anyone can help? Thanks!
A few things to check
Did you check the "Trigger builds remotely (e.g., from scripts)" option? If checked, there will be text box to enter your token.
Do you use security? If yes you have to authenticate against Jenkins.
Have a look at https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API (The statement that you need to use json to trigger parametrized builds is wrong)
I think you have to replace build
with buildWithParameters
in your URL.
var jqxhr = $.post(
"http://servername:8080/job/jab-name/buildWithParameters/api/json",
{ "parameters": [{ "PARAM1": "value1" }, { "PARAM2": "value2" }] },
"json"
)
.success(function () { alert("success"); })
.error(function (xhr, ajaxOptions, thrownError) { alert("Error\nxhr.status = [" + xhr.status + "]\n xhr.status: [" + xhr.statusText + "]\najaxOptions = [" + ajaxOptions + "]"); })
.complete(function () { alert("complete"); });
精彩评论