Jenkins / Hudson createItem API请求返回空格错误

时间:2013-06-07 14:53:21

标签: api rest jenkins hudson hudson-api

我正在尝试向Jenkins API提交POST以创建新作业。我按照API文档使用Postman来提出具体请求。

当我发出请求时,服务器返回ERROR 500并出现以下错误:

<html><head><title>Error 500</title></head>

状态代码:500

异常:无法读取/var/lib/jenkins/jobs/Tes234t6.dev/config.xml
Stacktrace:
hudson.util.IOException2: Unable to read /var/lib/jenkins/jobs/Tes234t6.dev/config.xml
    at hudson.XmlFile.read(XmlFile.java:145)
    at hudson.model.Items.load(Items.java:220)
    at hudson.model.ItemGroupMixIn.createProjectFromXML(ItemGroupMixIn.java:235)
    at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:167)
    at jenkins.model.Jenkins.doCreateItem(Jenkins.java:2876)
    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:288)
    at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:151)
    at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:90)
    at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:111)
    at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:677)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:770)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:583)
    at org.kohsuke.stapler.Stapler.service(Stapler.java:214)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
    at winstone.ServletConfiguration.execute(ServletConfiguration.java:248)
    at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:376)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:95)
    at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:87)
    at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:48)
    at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
    at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:174)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.ApiTokenFilter.doFilter(ApiTokenFilter.java:64)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
    at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
    at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
    at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
    at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:50)
    at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
    at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
    at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
    at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
    at winstone.RequestDispatcher.forward(RequestDispatcher.java:331)
    at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:227)
    at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
Caused by: com.thoughtworks.xstream.io.StreamException:  : only whitespace content allowed before start tag and not - (position: START_DOCUMENT seen -... @1:1) 
    at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
    at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
    at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
    at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:925)
    at hudson.XmlFile.read(XmlFile.java:143)
    ... 66 more
Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not - (position: START_DOCUMENT seen -... @1:1) 
    at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1519)
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
    at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
    at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)
    ... 75 more


由Stapler于7月7日星期五10:47:55在2013年东部时间生成

我看了一下我的config.xml文件,文件顶部没有空格。除此之外,我不确定它在说什么。我用Google搜索并查看了SO但没有发现任何与在CLI之外使用此API有关的内容。任何人都有成功的经验或指点吗?

这是我对API发布的帖子请求:

POST /createItem?name=Tes234t6.dev HTTP/1.1
Host: XXX.XXX.XXX.XXX:8080
Content-Type: text/xml
Authorization: Basic cm9vdDpjcm9zYnlhZG0xbg==
Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="config.xml"; filename="config.xml"
Content-Type: text/xml


----WebKitFormBoundaryE19zNvXGzXaLvS5C

2 个答案:

答案 0 :(得分:0)

尽管Jenkins API说要发布“config.xml”,但你实际上并没有发送文件,而是发布了xml数据。

我这样做的方法是使用Postman插件进行chrome,并将config.xml文件的内容直接添加到RAW输入。这对我有用。

希望这能让其他人感到沮丧。

答案 1 :(得分:0)

我也偶然发现了这个问题但你的解决方案对我们没有用。所以,如果有人谷歌搜索这个问题,这是另一种可能的解决方案。

我们的 Jenkins (通过AJP连接)前面有一个 Apache 。使用Jeknins版本1.534(或以下)时,一切正常。升级到1.535或更高版本后,我们在尝试通过REST-API创建作业时遇到上述错误。这并不是一直发生的,而是20个工作岗位中的一个。

事实证明,这只发生在通过Apache调用REST-API(然后使用ajp转发给Jeknins)时。解决方案是直接对Jenkins进行REST调用。


注意:jenkins 1.535 and above is using Jetty 8.