在使用像Hudson/Jenkins这样的CI工具时,如何使用GitHub(或GitHub企业)成功使用Maven版本插件

Sat*_*yaS 4 git github maven-3 maven maven-release-plugin

在使用像Hudson/Jenkins这样的CI工具时,如何使用GitHub(或GitHub企业)成功使用Maven版本插件

遇到的问题是

  • 如果pom.xml位于子文件夹而不是顶级文件夹中,则Maven不会提交.由于此后续构建失败,标记名称已存在.
  • 尽管在运行CI作业的源服务器之间设置了公钥认证,但git push失败并出现以下错误之一
    • 公钥验证失败
    • 未知的服务git

Sat*_*yaS 6

有许多事情需要正确才能发挥作用.

  1. 为了使pom.xml的子文件夹提交起作用,该错误在Maven release插件2.5.1中得到解决.获取最新的依赖项.以下部分显示了pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.1</version>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.scm</groupId>
                <artifactId>maven-scm-provider-gitexe</artifactId>
                <version>1.9.2</version>
            </dependency>
        </dependencies>
    
        <configuration>
            <checkModificationExcludes>
                <checkModificationExclude>pom.xml</checkModificationExclude>
            </checkModificationExcludes>
        </configuration>
    </plugin>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在pom.xml中正确配置SCM部分.要使公钥认证正常工作,请使用SSH协议.对于https协议,将需要用户/密码,此答案不包括此内容.应该可以通过在servers部分的Maven settings.xml中提供user/pwd来实现.

    <scm>
        <developerConnection>scm:git:ssh://github.com/org/repo.git</developerConnection>
        <url>https://github.com/org/repo</url>
        <tag>HEAD</tag>
    </scm>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在源服务器中创建一个名为git的用户.如果您像任何其他用户一样运行,则developerConnection url将需要git@github.com而不是github.com.Maven将尝试在git push命令中放置一个git:******,它因服务未知而失败.如果您使用任何其他用户SSH到github,它将拒绝公钥验证失败.

  4. 使用git作为用户,生成SSH密钥并按照以下简单步骤进行配置

    https://help.github.com/articles/generating-ssh-keys/

  5. 编辑您的Hudson/Jenkins工作,如下所示

    • 在源代码管理部分下,提供git repo的URL.您可能需要将git作为协议,因为某些CI安装不支持https.
    • 在分支机构中提及您的分支以构建(例如开发)
    • 单击高级并在"结帐/合并到本地分支(可选)"部分中添加相同的分支名称

使用maven目标运行你的工作清理编译版本:准备和发布:执行.它应该工作.