我想以编程方式从Java程序启动Maven发行版。该网页显示了一般的操作方法。这就是我所做的:
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); } }
该论坛建议“在发布之前,请先查看一下表格,您就应该能够提出cURL请求”,这就是我所做的。发行至少开始。
我现在不知道如何逃避一切。浏览器将空格显示为“ +”,但是如果我以这种方式发送数据,它将无法正常工作。实际上,“”,“ +”或“%20”都不用作空格。
我仍然可以Unable to commit files进入构建,因此我可以肯定用户名/密码/注释前缀有问题。即使已发送登录,Jenkins本身也会返回登录页面(“需要身份验证”)。
Unable to commit files
在Jenkins上触发Maven版本的正确方法是什么?
好的,我的旧方法中缺少的参数是:
writer.write("specifyScmCredentials=on&"); writer.write("specifyScmCommentPrefix=on&");