开发者

Trigger parametrized job build using remote API through ajax

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

  1. Did you check the "Trigger builds remotely (e.g., from scripts)" option? If checked, there will be text box to enter your token.

  2. Do you use security? If yes you have to authenticate against Jenkins.

  3. 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"); });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜