7

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.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);
    }
}

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
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Hello, as the imagebin link is invalid, I am not sure about your question. I have posted an answer for uploading a file for a parameterized build with curl at http://illegalstateexception.blogspot.de/2010/11/triggering-hudson-parameterized-builds.html. – Mirko Friedenhagen Mar 24 '12 at 21:40
  • I am having the same issue, did you fix this ? – tipu May 05 '12 at 03:40

1 Answers1

21

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

Olivier Lamy
  • 2,280
  • 1
  • 14
  • 12