git Maven - 将代码发布到 GitHub 时出错(推送后挂起)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3243755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven - Error Releasing Code to GitHub (Hangs After Push)
提问by Taylor Leese
I'm attempting to run the mvn release:prepare
goal and it's hanging after the push. Any idea what I could be doing wrong?
我正在尝试运行mvn release:prepare
目标,但它在推动后挂起。知道我可能做错了什么吗?
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESSFUL
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 8 seconds
[INFO] [INFO] Finished at: Tue Jul 13 23:54:59 PDT 2010
[INFO] [INFO] Final Memory: 55M/294M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Checking in modified POMs...
[INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git commit --verbose -F C:\Users\TAYLOR~1\AppData\Local\Temp\maven-scm-1932347225.commit pom.xml"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git symbolic-ref HEAD"
[INFO] Working directory: C:\development\taylor\my-app
[INFO] Executing: cmd.exe /X /C "git push [email protected]:tleese22/my-app.git master:master"
[INFO] Working directory: C:\development\taylor\my-app
>>>> hangs here <<<<
Below is the SCM section of my pom.xml:
下面是我的 pom.xml 的 SCM 部分:
<scm>
<connection>scm:git:git://github.com/tleese22/my-app.git</connection>
<developerConnection>scm:git:[email protected]:tleese22/my-app.git</developerConnection>
<url>http://github.com/tleese22/my-app</url>
</scm>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
Below is my .git/config:
下面是我的 .git/config:
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
bare = false
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "origin"]
url = [email protected]:tleese22/my-app.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = [email protected]:tleese22/my-app.git
Here's the result of git show origin:
这是 git show origin 的结果:
$ git remote show origin
Enter passphrase for key '/c/Users/Taylor Leese/.ssh/id_rsa':
* remote origin
Fetch URL: [email protected]:tleese22/my-app.git
Push URL: [email protected]:tleese22/my-app.git
HEAD branch: master
Remote branches:
gh-pages new (next fetch will store in remotes/origin)
master new (next fetch will store in remotes/origin)
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
$ git status
# On branch master
nothing to commit (working directory clean)
采纳答案by VonC
Considering the source of git builtin-push.c
, that means that somehow, no remote are defined for the local Git repo used by the maven script.
考虑到 的来源git builtin-push.c
,这意味着不知何故,没有为 maven 脚本使用的本地 Git 存储库定义远程。
static int do_push(const char *repo, int flags)
{
int i, errs;
struct remote *remote = remote_get(repo);
const char **url;
int url_nr;
if (!remote) {
if (repo)
die("bad repository '%s'", repo);
die("No destination configured to push to.");
}
As illustrated by this blog post, the maven config is not the all story.
正如这篇博客文章所示,maven 配置并不是全部。
~/foo/mikeci-archetype-springmvc-webapp$ git remote add origin [email protected]:amleggett/mikeci-archetype-springmvc-webapp.git
A remote add
is still required, before specifying the maven scm parameters:
remote add
在指定 maven scm 参数之前,仍然需要A :
Updating the POM
For Maven to function effectively, you should always ensure that you include project VCS information in your POM file.
Now that we've added the archetype to a Git repository we can include the appropriate<scm>
configuration:
更新 POM
为了让 Maven 有效运行,您应该始终确保在 POM 文件中包含项目 VCS 信息。
现在我们已经将原型添加到 Git 存储库中,我们可以包含适当的<scm>
配置:
<scm>
<connection>
scm:git:ssh://github.com/amleggett/${artifactId}.git
</connection>
<developerConnection>
scm:git:ssh://[email protected]/amleggett/${artifactId}.git
</developerConnection>
<url>
http://github.com/amleggett/${artifactId}
</url>
</scm>
The same blog post adds:
同一篇博文补充说:
It's important to understand the meaning of each of the child elements of
<scm>
.
- The
<connection>
element defines a read-only url and- the
<developerConnection>
element a read+write url.For both of these elements the url must adhere to the following convention:
了解 的每个子元素的含义很重要
<scm>
。
- 该
<connection>
元素定义了一个只读 url 和- 该
<developerConnection>
元素的读+写网址。对于这两个元素,url 必须遵守以下约定:
scm:<scm implementation>:<scm implementation-specific path>
- Finally, the
<url>
element content should point to a browsable location and for me this is the GitHub repository home page. Note that in all cases, I'm using an interpolated value which is my project artifactId.One handy tip is that you can verify this configuration by using the
maven-scm-plugin
.
This plugin offers ‘vendor' independent access to common VCS commands by offering a set of command mappings for the configured VCS. The validate goal should confirm all is well:
- 最后,
<url>
元素内容应该指向一个可浏览的位置,对我来说这是 GitHub 存储库主页。请注意,在所有情况下,我都使用了一个内插值,即我的项目 artifactId。一个方便的提示是,您可以使用
maven-scm-plugin
.
该插件通过为已配置的 VCS 提供一组命令映射,提供对常见 VCS 命令的“供应商”独立访问。验证目标应该确认一切正常:
~/foo/mikeci-archetype-springmvc-webapp$ mvn scm:validate
[INFO] Preparing scm:validate
[INFO] No goals needed for project - skipping
[INFO] [scm:validate {execution: default-cli}]
[INFO] connectionUrl scm connection string is valid.
[INFO] project.scm.connection scm connection string is valid.
[INFO] project.scm.developerConnection scm connection string is valid.
[INFO] --------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
回答by AWhitford
I have run into the same problem and I traced this to the fact that git is requiring a passphrase, but Maven has no way to specify an appropriate passphrase, so the process essentially hangs. Note that this problem is limited to Windows.
我遇到了同样的问题,我将其追溯到 git 需要密码的事实,但 Maven 无法指定适当的密码,因此该过程基本上挂起。请注意,此问题仅限于 Windows。
The solution is to run ssh-agent. This can be found in C:\Program Files (x86)\Git\bin\
. After you run it, it outputs some environment variables that you need to set. For example:
解决方案是运行ssh-agent。这可以在C:\Program Files (x86)\Git\bin\
. 运行后,它会输出一些您需要设置的环境变量。例如:
SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2792; export SSH_AGENT_PID;
echo Agent pid 2792;
SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924; 导出 SSH_AUTH_SOCK;
SSH_AGENT_PID=2792; 导出 SSH_AGENT_PID;
回声代理pid 2792;
So, you need to place these in your environment:
因此,您需要将这些放在您的环境中:
C:\> set SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924
C:\> set SSH_AGENT_PID=2792
C:\> set SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924
C:\> set SSH_AGENT_PID=2792
Then, you will need to add a passphrase for your particular key file. Generally, if you issued a command like git fetch origin master
for your project, you will get a passphrase prompt like: Enter passphrase for key '/c/Users/Anthony Whitford/.ssh/id_rsa'
-- that is the file that you need to register with the agent. So, the command is:
然后,您需要为特定的密钥文件添加密码。通常,如果您git fetch origin master
为您的项目发出类似命令,您将收到一个密码提示,例如: Enter passphrase for key '/c/Users/Anthony Whitford/.ssh/id_rsa'
-- 那是您需要向代理注册的文件。所以,命令是:
C:\> ssh-add "/c/Users/Anthony Whitford/.ssh/id_rsa"
C:\> ssh-add "/c/Users/Anthony Whitford/.ssh/id_rsa"
It will prompt you for a passphrase, so enter it. You should see an Identity added
message. Now, the agent knows the passphrase so that you will not be prompted to specify it anymore.
它会提示你输入密码,所以输入它。您应该会看到一条Identity added
消息。现在,代理知道密码短语,因此不会再提示您指定它。
If you have multiple instances of command prompts, make sure that each command prompt has the appropriate SSH_AUTH_SOCK and SSH_AGENT_PID environment variables set. You can validate that this is working by running a command like ssh -v [email protected]
and if you DO NOT get prompted for a passphrase, it is working!
如果您有多个命令提示符实例,请确保每个命令提示符都设置了适当的 SSH_AUTH_SOCK 和 SSH_AGENT_PID 环境变量。您可以通过运行类似的命令来验证这是否有效ssh -v [email protected]
,如果您没有收到输入密码的提示,则它正在工作!
Note that when you logoff, the ssh-agent will shut down and so when you log back in or restart your computer, you will need to repeat these steps. My understanding is that your passphrase is stored in memory, not persisted to disk, for security reasons.
请注意,当您注销时,ssh-agent 将关闭,因此当您重新登录或重新启动计算机时,您需要重复这些步骤。我的理解是,出于安全原因,您的密码存储在内存中,而不是保存在磁盘中。
回答by greglevilain
The mvn release:prepare
goal always runs in non-interactive mode, so you can't enter the ssh passphrase git is waiting for while pushing to the remote repository.
You can use an SSH agent to manage that, but if this problem only appears during the release process, there is another solution : preparing the release locally, and pushing the tag afterwards.
该mvn release:prepare
目标始终以非交互模式运行,因此您无法输入 git 在推送到远程存储库时正在等待的 ssh 密码。您可以使用 SSH 代理来管理它,但如果此问题仅在发布过程中出现,还有另一种解决方案:在本地准备发布,然后推送标签。
For this you have to use version 2.1+ of maven-release-pluginthat comes with the pushChanges
parameter.
为此,您必须使用参数附带的maven-release-plugin2.1+ 版pushChanges
。
mvn -DpushChanges=false release:prepare
By the way, your tag is created into your local GIT repository and you can then push it to the remote repository as usual, with a git push
command.
顺便说一下,您的标签已创建到本地 GIT 存储库中,然后您可以像往常一样使用git push
命令将其推送到远程存储库。
This method is useful for Eclipse users because Eclipse comes with an embedded ssh-agent but this agent is not used by maven while performing a release:prepare, even when using eGit.
此方法对 Eclipse 用户很有用,因为 Eclipse 带有一个嵌入式 ssh-agent,但是 maven 在执行 release:prepare 时不使用该代理,即使在使用 eGit 时也是如此。
回答by Tushar
These are the exact sequence of commands I followed to get rid of this error
这些是我为摆脱此错误而遵循的确切命令序列
C:\Program Files (x86)\Git\bin>bash
bash-3.1$ eval 'ssh-agent -s'
SSH_AUTH_SOCK=/tmp/ssh-ZARFN11804/agent.11804; export SSH_AUTH_SOCK;
SSH_AGENT_PID=10284; export SSH_AGENT_PID;
echo Agent pid 10284;
bash-3.1$ exec ssh-agent bash
bash-3.1$ ssh-add "/c/Users/idntus/.ssh/id_rsa"
Enter passphrase for /c/Users/idntus/.ssh/id_rsa:
Identity added: /c/Users/idntus/.ssh/id_rsa (/c/Users/idntus/.ssh/id_rsa)
bash-3.1$ mvn release:prepare release:perform
回答by MantasG
The only thing which worked for me was specifying GIT user name and password as maven parameters:
唯一对我有用的是将 GIT 用户名和密码指定为 maven 参数:
mvn -Dusername=jenkins -Dpassword=******** release:prepare release:perform
To hide password in Jenkins output console I installed and configured Mask Passwords Plugin.
为了在 Jenkins 输出控制台中隐藏密码,我安装并配置了 Mask Passwords Plugin。
回答by Hzmy
Yet another reason it could hang is if github.com
isn't in the known_hosts
file. SSH will therefore hang waiting for the user to accept authenticity of the host.
它可能挂起的另一个原因是如果github.com
不在known_hosts
文件中。因此,SSH 将挂起等待用户接受主机的真实性。
To add github.com
to your known hosts just do a quick SSH to it: ssh github.com
. The SSH client will then ask you to confirm the authenticity of the host. Type "Yes" and it'll say that its permanently added github.com
to your list of known hosts.
要添加github.com
到您的已知主机,只需对其进行快速 SSH:ssh github.com
. SSH 客户端然后会要求您确认主机的真实性。输入“是”,它会说它已永久添加github.com
到您的已知主机列表中。
回答by trigged
I had faced the same problem, I had tried many ways but got to resolved it with below steps:
我遇到了同样的问题,我尝试了很多方法,但必须通过以下步骤解决它:
1. you need check git origin
1.你需要检查git来源
2. update your pom.xml,find scm section,
2. 更新你的 pom.xml,找到 scm 部分,
change github ssh address the `:` to '/'
before
<scm>
<connection>scm:git:ssh://[email protected]:xxx/xxxin.git</connection>
<developerConnection>scm:git:ssh://[email protected]:xxx/xxxin.git</developerConnection>
<url>https://github.com/xxx/jenkins-xxx-plugin</url>
<tag>HEAD</tag>
</scm>
then
<scm>
<connection>scm:git:ssh://[email protected]/xxx/xxxin.git</connection>
<developerConnection>scm:git:ssh://[email protected]/xxx/xxxin.git</developerConnection>
<url>https://github.com/xxx/jenkins-xxx-plugin</url>
<tag>HEAD</tag>
</scm>
3. set ~/.m2/settings.xml
3.设置~/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven.jenkins-ci.org</id> <!-- For parent 1.397 or newer; before this use id java.net-m2-repository -->
<username>your jenkins username</username>
<password>your jenkins password</password>
</server>
</servers>
4. then commit & push your changes
4.然后提交并推送您的更改
5. run mvn release:prepare release:perform
5. 运行 mvn release:prepare release:perform
回答by Sabine
I had the same issue. I tried all the above solutions and still it did not work.
我遇到过同样的问题。我尝试了上述所有解决方案,但仍然无效。
That was because I was still doing one thing wrong: for the ssh commands I used git bash while for the maven command I used the command prompt. And there not all the git commands were available.
那是因为我仍然做错了一件事:对于 ssh 命令,我使用了 git bash 而对于 maven 命令,我使用了命令提示符。并不是所有的 git 命令都可用。
After adding the complete git bin folder to the PATH variable everything worked for me.
将完整的 git bin 文件夹添加到 PATH 变量后,一切都对我有用。