2015-10-14 100 views
0

我想用maven克隆存储库,并且认证必须使用现有的ssh-agent。如何使用使用ssh-agent的maven克隆克隆?

我当前插件配置:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-scm-plugin</artifactId> 
    <version>1.9.4</version> 
    <configuration> 
     <providerImplementations> 
       <git>jgit</git> 
     </providerImplementations> 
    </configuration> 
    <dependencies> 
     <dependency> 
       <groupId>org.apache.maven.scm</groupId> 
       <artifactId>maven-scm-provider-jgit</artifactId> 
       <version>1.9.4</version> 
     </dependency> 
    </dependencies> 
    <executions> 
     <execution> 
      <id>clone-github-wiki</id> 
      <goals> 
       <goal>checkout</goal> 
      </goals> 
      <phase>generate-resources</phase> 
      <configuration> 
       <checkoutDirectory>${project.basedir}/target/github-wiki</checkoutDirectory> 
       <connectionType>connection</connectionType> 
       <connectionUrl>scm:git:[email protected]:xyz/abc.wiki.git</connectionUrl> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

认证失败:

[INFO] --- maven-scm-plugin:1.9.4:checkout (clone-github-wiki) @ xyz-doc --- 
[INFO] Change the default 'git' provider implementation to 'jgit'. 
[INFO] Removing /home/jenkins/abc/doc/target/github-wiki 
[INFO] cloning [master] to /home/jenkins/abc/doc/target/github-wiki 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.490 s 
[INFO] Finished at: 2015-10-14T11:45:40+02:00 
[INFO] Final Memory: 15M/241M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-scm-plugin:1.9.4:checkout (clone-github-wiki) on project xyz-doc: Cannot run checkout command : Exception while executing SCM command. JGit checkout failure! [email protected]:abc/xyz.wiki.git: Auth fail -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 

回答

0

Exec插件可被用来调用git的命令。在这种情况下,使用ssh代理。

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.3.2</version> 
    <executions> 
     <execution> 
      <id>github-wiki-clone</id> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <phase>generate-resources</phase> 
      <configuration> 
       <executable>git</executable> 
       <arguments> 
        <argument>clone</argument> 
        <argument>-b</argument> 
        <argument>master</argument> 
        <argument>[email protected]:abc/xyz.wiki.git</argument> 
        <argument>target/github-wiki</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin>