Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Hudson » Hudson remote api usage(Hudson remote api usage)
Hudson remote api usage [message #1058474] Tue, 14 May 2013 09:50 Go to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
I want to use hudson remote apis to create job,build jobs.
To create job i have used the below code,

The job is created,but the response i got is 400 error,Bad request.
Shall i use the config.xml present in jobs folder for one of the jobs which i have created earlier.
Please explain the reason for 400 error and how come the job got created.
Please help me out in solving this.
Re: Hudson remote api usage [message #1058749 is a reply to message #1058474] Tue, 14 May 2013 21:06 Go to previous messageGo to next message
Bob Foster is currently offline Bob FosterFriend
Messages: 74
Registered: January 2013
Member
What code?

What version of Hudson are you running? Do you have authentication on?

Thanks.
Re: Hudson remote api usage [message #1059541 is a reply to message #1058749] Mon, 20 May 2013 11:36 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi All,

Running Hudson as the service in 8080 port.Iam have wrote sample java code to create job in hudson and trigger it from the remote windows machine.The config.xml is taken from the jobs folder of another job:
But it is throwing 500 error(Response status code: 500
package createJob;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;




public class CreateJob {

	public static void main(String[] args) throws FileNotFoundException {
		String strURL = "htt://XXXX:8080/createItem?name=findsresume123";
		File input = new File("C:\\Users\\XXXX\\Desktop\\config.xml");
		PostMethod post = new PostMethod(strURL);
		post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));


		post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
		HttpClient httpclient = new HttpClient();

		try {

            int result = httpclient.executeMethod(post);
            System.out.println("Response status code: " + result);
            System.out.println("Response body: ");
            System.out.println(post.getResponseBodyAsString());
		}
		catch (Exception e) {
            // Release current connection to the connection pool 
            // once you are done
            post.releaseConnection();
        }
		



		
		// TODO Auto-generated method stub

	}

}




Response body: 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 500 Unable to read /var/lib/hudson/jobs/yyyy/config.xml</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /createItem. Reason:
<pre>    Unable to read /var/lib/hudson/jobs/yyyy/config.xml</pre></p><h3>Caused by:</h3><pre>hudson.util.IOException2: Unable to read /var/lib/hudson/jobs/yyyy/config.xml
	at hudson.XmlFile.read(XmlFile.java:119)
	at hudson.model.Items.load(Items.java:113)
	at hudson.model.ItemGroupMixIn.createProjectFrom
        at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:161)
	at hudson.model.Hudson.doCreateItem(Hudson.java:2676)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:274)
	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:141)
	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:80)
	at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:95)
	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:45)
	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:565)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:650)
	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:481)
	at org.kohsuke.stapler.Stapler.service(Stapler.java:152)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:648)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:86)
	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:78)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:81)
	at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:73)
	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:157)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:70)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:534)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:365)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:679)
Caused by: com.thoughtworks.xstream.converters.ConversionException:  : no more data available - expected end tag &lt;/project&gt; to close start tag &lt;project&gt; from line 2, parser stopped on END_TAG seen ...&lt;builders/&gt;\r\n... @205:1 :  : no more data available - expected end tag &lt;/project&gt; to close start tag &lt;project&gt; from line 2, parser stopped on END_TAG seen ...&lt;builders/&gt;\r\n... @205:1
---- Debugging information ----
...............


I have not turn on authentication.
version-hudson-3.0.1.If i need turn on authentication please explain the steps too.
Please help me out in resolving this

[Updated on: Tue, 21 May 2013 12:12]

Report message to a moderator

Re: Hudson remote api usage [message #1059626 is a reply to message #1059541] Mon, 20 May 2013 21:54 Go to previous messageGo to next message
Winston Prakash is currently offline Winston PrakashFriend
Messages: 449
Registered: August 2011
Location: Fremont, CA USA
Senior Member
You should not use createItem directly. You should use the remote Access API as explained here http://wiki.hudson-ci.org/display/HUDSON/Remote+access+API.

Winston Prakash
Eclipse Hudson team
Re: Hudson remote api usage [message #1059743 is a reply to message #1059626] Tue, 21 May 2013 13:24 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi,
I have configured security and enabled it as mentioned in the url:
http://wiki.hudson-ci.org/display/HUDSON/Standard+Security+Setup
I have created users and give all permissions to create job
I have modified the code as accessing the url with username and password which i created now.
Create Job
I have created the job as mentioned below in the site.

To create a new job, POST config.xml to http://your_server/createItem (copy url) with query parameter name=JOBNAME.
You'll get 200 status code if the creation is successful, or 4xx/5xx code if it fails. config.xml is the format Hudson uses to store the job in the file system, so you can see examples of them in /var/lib/hudson.

I have tried the code as mentioned in the site:"http://wiki.hudson-ci.org/display/HUDSON/Authenticating+scripted+clients"

There also they have used the createItem directly.

Can you please explain briefly,so that it can be useful for me.
Thanks.

[Updated on: Tue, 21 May 2013 13:25]

Report message to a moderator

Re: Hudson remote api usage [message #1059997 is a reply to message #1059743] Wed, 22 May 2013 13:38 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi,

Please help me out in resolving this.

Thanks,
HariPrasadh
Re: Hudson remote api usage [message #1060060 is a reply to message #1059997] Wed, 22 May 2013 18:33 Go to previous messageGo to next message
Winston Prakash is currently offline Winston PrakashFriend
Messages: 449
Registered: August 2011
Location: Fremont, CA USA
Senior Member
I'll look at it and get back to you.

Winston Prakash
Eclipse Hudson team
Re: Hudson remote api usage [message #1060079 is a reply to message #1060060] Thu, 23 May 2013 01:38 Go to previous messageGo to next message
Winston Prakash is currently offline Winston PrakashFriend
Messages: 449
Registered: August 2011
Location: Fremont, CA USA
Senior Member
Mean while you can take a look at Hudson Job Creator tool

Winston Prakash
Eclipse Hudson team
Re: Hudson remote api usage [message #1060936 is a reply to message #1060079] Wed, 29 May 2013 08:43 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Thanks winston.I ran the same code today.It ran properly and created job with status code 200(success).
Re: Hudson remote api usage [message #1062209 is a reply to message #1060936] Thu, 06 June 2013 14:10 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi Winston,

Now iam getting problem in triggering the build remotely.
The code is

public String buildjob()
{

String strURL1="htt://xxxx:8080/job/"+jobname+"/build?delay=0sec";
PostMethod post = new PostMethod(strURL1);
HttpClient httpclient = new HttpClient();
httpclient.getState().setCredentials(new AuthScope("xxxx", 8080, "realm"),new UsernamePasswordCredentials("xxxx", "zzzz"));
httpclient.getParams().setAuthenticationPreemptive(true);
try {

int result = httpclient.executeMethod(post);


System.out.println("Build Response status code: " + result);
System.out.println("Build Response body: ");
System.out.println(post.getResponseBodyAsString());


}
}
catch (Exception e) {
// Release current connection to the connection pool
// once you are done
post.releaseConnection();
}
return res;
}

Iam getting 302 response code.buthe build is happening at hudson end.i was not able to get the build is success/failure.
Please share some idea to get the build no,build status and check the above code and let me know.
Thanks


Re: Hudson remote api usage [message #1062361 is a reply to message #1062209] Fri, 07 June 2013 12:16 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi,

Please check the above issue.its little urgent.
Thanks,
HariPrasadh
Re: Hudson remote api usage [message #1063474 is a reply to message #1062361] Thu, 13 June 2013 09:24 Go to previous messageGo to next message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hi,
Please someone reply me to my above query.
Thanks,
HariPrasadh
Re: Hudson remote api usage [message #1063653 is a reply to message #1063474] Thu, 13 June 2013 15:23 Go to previous messageGo to next message
Winston Prakash is currently offline Winston PrakashFriend
Messages: 449
Registered: August 2011
Location: Fremont, CA USA
Senior Member
Hari, let us take this offline. Send me an e-mail at winston DOT prakash AT gmail DOT com. Once you have a correct solution you can post it here.

Winston Prakash
Eclipse Hudson team
Re: Hudson remote api usage [message #1065360 is a reply to message #1063653] Tue, 25 June 2013 12:32 Go to previous message
hariprasadh balasubramanian is currently offline hariprasadh balasubramanianFriend
Messages: 18
Registered: April 2013
Junior Member
Hello Wiston,

I have sent a mail to you stating the problem.Please help.


Thanks
HariPrasadh
Previous Topic:How can we execute Hudson\Jenkins Job using logged on user credential
Next Topic:svn update with revert not working
Goto Forum:
  


Current Time: Sat Dec 20 18:46:32 GMT 2014

Powered by FUDForum. Page generated in 0.02197 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software