开发者

File upload + parameter via HTTP POST to trigger a Hudson build

开发者 https://www.devze.com 2023-01-29 22:23 出处:网络
Currently i\'m searching for a working method to upload a file + a field in the following confiuguration of Hudson. The current problem is that Hudson always complains about a form which should be sub

Currently i'm searching for a working method to upload a file + a field in the following confiuguration of Hudson. The current problem is that Hudson always complains about a form which should be submitted..(see exception later in this post). But based on the docs i read it should be working like the following Java code snippet...

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.getS开发者_StackOverflow社区tatusLine().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);
    }
}

My current Maven dependencies are as follows:

<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>

The exception is this:

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


you are probably using url like job/blabla/build you must try with job/blabla/buildWithParameters

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号