【问题标题】:File upload + parameter via HTTP POST to trigger a Hudson build通过 HTTP POST 上传文件 + 参数以触发 Hudson 构建
【发布时间】:2011-05-22 20:30:33
【问题描述】:

目前我正在寻找一种在Hudson的以下配置中上传文件+字段的工作方法。当前的问题是 Hudson 总是抱怨应该提交的表单..(请参阅本文后面的异常)。但根据我阅读的文档,它应该像下面的 Java 代码 sn-p...

HttpPost httppost = new HttpPost(triggerJobUrl);
FileBody fileBody = new FileBody(releaseProperties);
StringBody stringBody = new StringBody(svnURL.toString());
MultipartEntity mentity = new MultipartEntity();
mentity.addPart("trunk/release.properties", fileBody);
mentity.addPart("SVNURL", stringBody);
httppost.setEntity(mentity);
HttpResponse response = null;
try {
    response = httpClient.execute(httppost);
} catch (ClientProtocolException e) {
    throw new HudsonException("http protocol error.", e);
} catch (IOException e) {
    throw new HudsonException("connection aborted.", e);
}
if (response.getStatusLine().getStatusCode() != 200) {
    throw new HudsonException("Unexpected status code received " + response.getStatusLine().getStatusCode());
}
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
    try {
        resEntity.consumeContent();
    } catch (IOException e) {
        throw new HudsonException(
                "if an I/O error occurs. This indicates that connection keep-alive is not possible.", e);
    }
}

我目前的Maven依赖如下:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.0.3</version>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpcore</artifactId>
  <version>4.0.1</version>
  <type>jar</type>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpmime</artifactId>
  <version>4.0.3</version>
  <type>jar</type>
  <scope>compile</scope>

例外是这样的:

java.lang.Error: This page expects a form submission
   at org.kohsuke.stapler.RequestImpl.getSubmittedForm(RequestImpl.java:769)
   at hudson.model.ParametersDefinitionProperty._doBuild(ParametersDefinit

【问题讨论】:

  • 您好,由于 imagebin 链接无效,我不确定您的问题。我已经在illegalstateexception.blogspot.de/2010/11/… 发布了使用 curl 上传参数化构建文件的答案。
  • 我也遇到了同样的问题,你解决了吗?

标签: java http hudson httpclient hudson-api


【解决方案1】:

您可能正在使用类似 job/blabla/build 的 url,您必须尝试使用​​ job/blabla/buildWithParameters

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多