如何使用curl触发jenkins作业并在url中传递参数

时间:2016-03-21 05:10:50

标签: jenkins build

我正在尝试使用curl命令触发jenkins构建。以下是我的命令

http://localhost:8080/view/Project%20IRT/job/create_image/buildWithParameters?token=sprit&Action="blah blah"&ClientName="morang"

它给出了以下错误并使用我在作业中定义的默认参数触发构建

'Action' is not recognized as an internal or external command,
operable program or batch file.
'ClientName' is not recognized as an internal or external command,
operable program or batch file.

我在这里缺少什么。如何在url中传递参数来触发一个job.I也尝试这样做但是在命令下面没有成功给json错误。

curl -X POST http://localhost:8080/view/Project%20IRT/job/create_image/build --data token=sprit --data-urlencode json='{"parameter": [{"name":"Action", "value":"blah blah"},{"name":"ClientName", "value":"morang"}]}'

JSONERROR ; -

Caused by: net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of '{parameter:
        at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:499)
        at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:919)
        at net.sf.json.JSONObject._fromString(JSONObject.java:1145)
        at net.sf.json.JSONObject.fromObject(JSONObject.java:162)
        at net.sf.json.JSONObject.fromObject(JSONObject.java:132)
        at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:916)
        ... 81 more
</pre></div></div></div><footer><div class="container-fluid"><div class="row"><div class="col-md-6" id="footer"></div><div class="col-md-18"><span class="page_generated">Page generated:
 Mar 21, 2016 10:39:05 AM IST</span><span class="rest_api"><a href="api/">REST API</a></span><span class="jenkins_ver"><a href="http://jenkins-ci.org/">Jenkins ver. 1.644</a></span><div
 id="l10n-dialog" class="dialog"></div><div id="l10n-footer" style="display:none; float:left"><a href="#" onclick="return showTranslationDialog();"><img src="/static/fbacd7a6/plugin/tra
nslation/flags.png" />
      Help us localize this page
    </a></div><script>var footer = document.getElementById('l10n-footer');
    var f = document.getElementById('footer');
    f.insertBefore(footer,f.firstChild);
    footer.style.display="block";

    var translation={};
    translation.bundles = "mC177+QPH0ukSUfPbWxfIyQw/DlaO16MmOglhwDdqW6lL/PyzHLaYsioVPvSoTyYFpwCaSkCkRllDVhBqkkft89+rzGakHYKf4ZR3PT0B4HF31sxwlLtogh+g+d5ujrwV53UuNzg67Bb9U4lYNodstxN3fuv/F
cnebyjHpcQPci0zoAkJbd7YJIX3LaNdkuvdoPZmneCtaMjG5camLnbJM+pj9v4BHCQy9gooUl+aIDIuuhLiblKIVXFQfI4UbW2sGYNWluX4qn1iEyeBJGS6kNHKE05r2E5z9X5CVxcvHPb99pTDgBNqhc+WCDdN1d6PM7ueps55Mo/8v5ywsHGE9D
LlfvzHbmfu8Lg+JaQSZK2IKVvN55Ofr9x/4dgeE0khYjkodFSVo8Q/knoFjYZ/tWyIKyXJJrc6OJ40V29iOTF/KNHKFPWZOFueBUyDLiPEClcCMgA6iUB9vbzkFicKLvsTj+cQUAxjzL+8n4Vxh31qmVF/Md+8SdAfI0eau1F";
    translation.detectedLocale = "";

    function showTranslationDialog() {
      if(!translation.launchDialog)
        loadScript("/static/fbacd7a6/plugin/translation/dialog.js");
      else
        translation.launchDialog();
      return false;
    }</script></div></div></div></footer></body></html>curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] unmatched close brace/bracket in column 16
curl: (3) [globbing] unmatched close brace/bracket in column 13

1 个答案:

答案 0 :(得分:0)

你只是在&#34;&amp;&#34;之前错过了逃脱角色。它应该像&#34; ^&amp;&#34;。这有助于我,并在我的情况下工作。

所以,代码看起来像:

...job/create_image/buildWithParameters?token=sprit&Action="blah blah"^&ClientName="morang"