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

1

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
Jeweller answered 9/12, 2010 at 12:53 Comment(2)
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 illegalstateexception.blogspot.de/2010/11/….Bend
I am having the same issue, did you fix this ?Lugsail
R
21

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

Retrench answered 9/10, 2012 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.