如何在使用类似Hudson/Jenkins的CI工具时,成功地将Maven发布插件与GitHub(或GitHub企业版)结合使用?

4

如何在使用Hudson/Jenkins这样的CI工具时,成功地将Maven发布插件与GitHub(或GitHub企业版)配合使用

遇到的问题包括:

  • 如果pom.xml在子文件夹中而不是顶层,则Maven不会提交。由于这个问题,后续构建会因标签名称已存在而失败。
  • 尽管在运行CI作业的源服务器之间设置了公钥身份验证,但git push仍然会失败并显示以下错误之一
    • 公钥身份验证失败
    • 未知服务git

2
在子文件夹中放置父级文件并不是一个好的做法。这会使所有的pom文件变得比必要的更加复杂等。 - khmarbaise
1个回答

6
这需要多个方面都正确才能正常工作。
  1. For the sub-folder commit of pom.xml to work, the bug is resolved in Maven release plug-in 2.5.1. Get the latest with the dependencies. The below section shows the 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>
    
  2. Correctly configure the SCM section in pom.xml. For public key authentication to work, use SSH protocol. For https protocol, user/password will be needed, this answer does not cover that. It should be possible by providing user/pwd in the Maven settings.xml in the servers section.

    <scm>
        <developerConnection>scm:git:ssh://github.com/org/repo.git</developerConnection>
        <url>https://github.com/org/repo</url>
        <tag>HEAD</tag>
    </scm>
    
  3. Create a user called git in your source server. If you run as any other user, the developerConnection url will need to have git@github.com in stead of github.com. Maven will try to put a git:****** in the git push command and it fails as service unknown. If you use any other user to SSH into github, it will reject with public key authentication failed.

  4. Using the git as user, generate SSH keys and configure following the simple steps below

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

  5. Edit your Hudson/Jenkins job as below

    • Under the source code management section, provide the URL of the git repo. You might need to put git as protocol as some CI installs do not support https.
    • Mention your branch in branches to build (e.g. development)
    • Click advanced and put the same branch name in the section "Checkout/merge to local branch (optional)"

请使用maven命令 clean compile release:prepare和release:perform运行您的工作。这应该有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接