I want to start a Maven release programmatically from a Java program. This webpage shows how that is done generally. So that's what I did:
final URL url = new URL("http://jenkins/job/MyProject/m2release/submit");
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
final String userpass = "User:Password";
final String authentication = "Basic " + DatatypeConverter.printBase64Binary(userpass.getBytes());
urlConnection.setRequestProperty("Authorization", authentication);
try (final OutputStream os = urlConnection.getOutputStream();
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));) {
writer.write("releaseVersion=1.2.3&");
writer.write("developmentVersion=1.2.4-SNAPSHOT&");
// writer.write("isDryRun=on&"); // uncomment for dry run
writer.write("scmUsername=User&");
writer.write("scmPassword=Password&");
writer.write("scmCommentPrefix=[test]&");
writer.write("json={\"releaseVersion\":\"1.2.3\",\"developmentVersion\":\"1.2.4-SNAPSHOT\",\"isDryRun\":false}&");
writer.write("Submit=Schedule Maven Release Build");
writer.flush();
}
urlConnection.connect();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(urlConnection.getInputStream(), "UTF-8"))) {
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
}
This forum suggests "just have a look at the form befor you do a release and you should be able to craft a cURL request", that's what I did to get that far. The release starts at least.
I just don't now how to escape everything. The browser shows spaces as "+", but it does not work if I send the data that way. In fact, neither " ", "+" nor "%20" works as a space.
Still I get Unable to commit files
in the build, so I'm pretty sure something is wrong with the username / password / comment prefix. The Jenkins itself returns the log-in page ("Authentication required"), even though the log-in is send.
What is the correct way to trigger a Maven Release on a Jenkins?