远程触发Maven发布 [英] Trigger Maven Release Remotely

查看:98
本文介绍了远程触发Maven发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式从Java程序启动Maven发行版. 此网页显示了一般的操作方法.这就是我所做的:

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

此论坛建议只要看一下您发布的表格,您就可以编写cURL请求了",这就是我所做的.发行至少开始.

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.

我现在不知道如何逃避一切.浏览器将空格显示为"+",但是如果我以这种方式发送数据,它将无法正常工作.实际上,","+"或%20"都不是空格.

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.

仍然在构建中得到Unable to commit files,所以我很确定用户名/密码/注释前缀有问题.即使发送登录,Jenkins本身也会返回登录页面(需要身份验证").

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.

在Jenkins上触发Maven版本的正确方法是什么?

What is the correct way to trigger a Maven Release on a Jenkins?

推荐答案

好的,我的旧方法中缺少的参数是:

Okay, the parameters missing in my old approach were:

writer.write("specifyScmCredentials=on&");
writer.write("specifyScmCommentPrefix=on&");

这篇关于远程触发Maven发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆