我想使用 maven 克隆存储库,并且身份验证必须使用现有的 ssh-agent。
我当前的插件配置:
<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:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a1d130e3a1d130e120f1854191517" rel="noreferrer noopener nofollow">[email protected]</a>: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! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d6a64794d6a647965786f236e6260" rel="noreferrer noopener nofollow">[email protected]</a>: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:
最佳答案
exec 插件可用于调用 git 命令。在这种情况下,将使用 ssh-agent。
<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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80e7e9f4c0e7e9f4e8f5e2aee3efed" rel="noreferrer noopener nofollow">[email protected]</a>:abc/xyz.wiki.git</argument>
<argument>target/github-wiki</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
关于git - 如何使用 ssh 代理通过 Maven 进行 git 克隆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33122525/