通过HTTPS使用git-release-plugin和git

时间:2016-03-28 17:58:12

标签: git maven maven-release-plugin

我正在尝试使用带有git over maps的maven release插件(出于某些不明原因,我不能在ssh上使用git),但是,我收到以下错误消息:

14:36:52 [ERROR] The git-push command failed.
14:36:52 [ERROR] Command output:
14:36:52 [ERROR] fatal: could not read Username for 'https://my.company.git.host.com': No such device or address
14:36:52 [ERROR] -> [Help 1]

浏览网页,我想在 pom.xml 文件中设置以下属性:

<scm>
    <connection>scm:git:https://my.company.git.host.com/Project/project.git</connection>
    <developerConnection>scm:git:https://my.company.git.host.com/Project/project.git</developerConnection>
</scm>

以下内容已添加到我的 settings.xml (位于~/.m2文件夹下。我已通过运行带有-X标记的maven检查了这一点

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                  https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>my.company.git.host.com</id>
            <username>svc.jenkins.project</username>
            <password>guesswhat</password>
        </server>
    </servers>
</settings>

重要提示: 如果我直接在connectiondeveloperConnection属性中添加用户/密码,例如bellow,它就能正常运行。

<scm>
    <connection>scm:git:https://user:password@my.company.git.host.com/Project/project.git</connection>
    <developerConnection>scm:git:https://user:password@my.company.git.host.com/Project/project.git</developerConnection>
</scm>

这是对的吗?我的猜测是发布插件与git over https不兼容,但我会得到一些确认。

2 个答案:

答案 0 :(得分:2)

经过一些研究,我的结论是,当与https连接一起使用时,发布插件无法从外部文件恢复密码。因此,我发现的最佳方法是在网址中提供密码,格式如下:

<scm>
    <connection>scm:git:https://user:password@my.company.git.host.com/Project/project.git</connection>
    <developerConnection>scm:git:https://user:password@my.company.git.host.com/Project/project.git</developerConnection>

</scm>

答案 1 :(得分:2)

我知道这个问题很老,但是现在发现了。调用maven prepare时,可以在命令行参数中设置用户和密码:

mvn release:prepare -DreleaseVersion=1.2 -DdevelopmentVersion=2.0-SNAPSHOT -Dtag=my-tag1.2 -Dusername=YYYYY -Dpassword=XXXXXX

与mavern-release-plugin 2.5.3一起使用

此致