trigger job via API

22 views
Skip to first unread message

Louis Roché

unread,
May 30, 2013, 11:21:03 AM5/30/13
to jenkins...@googlegroups.com
Hi,

I try to trigger a job via the api with a parameter.

With curl, it works:

curl -X POST "http://192.168.5.230:8080/job/Generate%20new%20reference%20files/build?token=toto" --data 'json={"parameter":[{"name":"exchange_revision","value":"superargument"}]}'

But I want to do it from javascript.

<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script>
function httpPost(theUrl, Params)
    {
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    alert(Params);
    xmlHttp.open( "POST", theUrl, false );
    xmlHttp.send( Params );
    return xmlHttp.responseText;
    }
</script>
<button
  type='button'
  onclick='javascript:
  var params = JSON.stringify({parameter: [{name: "exchange_revision", value: "superargument"}]});
  var test = "json={\"parameter\":[{\"name\":\"exchange_revision\",\"value\":\"superargument\"}]}";
  httpPost("http://192.168.5.230:8080/job/Generate new reference files/build?token=toto", test)'>
  Start matrix
</button>
</html>

This request return a 400 and doesn't trigger the build.

I can't use buildWithParameters cause I can have strings in UCS2, UTF8, iso-* like 総組立. Or maybe it is possible, but I didn't find how.
 
Please, help me.

Thanks

Louis

Louis Roché

unread,
May 31, 2013, 4:00:29 AM5/31/13
to jenkins...@googlegroups.com
Ok, I can send params now, but I have a problem with the charset. If I send "E63H 総組立" as the value of exchange_revision, I receive "E63H �D�".

My code:


<html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script>
function httpPost(theUrl, Params) {
    var xmlHttp = null;
    xmlHttp = new XMLHttpRequest();
    alert(Params);
    xmlHttp.open( "POST", theUrl, false );
    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');

    xmlHttp.send( Params );
    return xmlHttp.responseText;
    }
</script>
<button
  type='button'
  onclick='javascript:
  var params = JSON.stringify({parameter: [{name: "exchange_revision", value: "E63H 総組立"}]});
  httpPost("http://192.168.5.230:8080/job/Generate new reference files/build?token=toto", "json="+params)'>
  Start matrix
</button>
</html>

Louis Roché

unread,
May 30, 2013, 11:54:28 AM5/30/13
to jenkins...@googlegroups.com
Ok, it seems that you need to add xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');


2013/5/30 Louis Roché <ma...@louisroche.net>

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/kCqmG9oK58I/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages