git Maven 和 Gitlab:release:prepare 使用了错误的 SCM URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29120076/
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 and Gitlab: release:prepare uses the wrong SCM URL
提问by rabejens
I am trying to do mvn release:prepare
on a multi-module project which is hosted on a Gitlab server.
我正在尝试做mvn release:prepare
一个托管在 Gitlab 服务器上的多模块项目。
The pom.xml
for my master POM contains:
在pom.xml
我的主POM包含:
<scm>
<connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git</connection>
<url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>
When I do mvn release:prepare -DautoVersionSubmodules=true
, it compiles everything and runs the test, but then fails with:
当我这样做时mvn release:prepare -DautoVersionSubmodules=true
,它编译所有内容并运行测试,但随后失败:
[INFO] Executing: /bin/sh -c cd /home/somebody/git/my-project && git tag -F /tmp/maven-scm-1594218362.commit my-project-1.0.0
[INFO] Working directory: /home/somebody/git/my-project
[INFO] Executing: /bin/sh -c cd /home/somebody/git/my-project && git push http://my-git-server.example.com/git/somebody my-project-1.0.0
[INFO] Working directory: /home/somebody/git/my-project
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project iwes-lib-master: Unable to tag SCM
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: repository 'http://my-git-server.example.com/git/somebody/' not found
[ERROR] -> [Help 1]
So it is telling me the maven-release-plugin thinks that the parent directory to my Git repository is the repository, bailing out there.
所以它告诉我 maven-release-plugin 认为我的 Git 存储库的父目录是存储库,在那里保释。
Adding a developerConnection
does not help.
添加一个developerConnection
没有帮助。
When trying to use SVN, it fails with "Access Denied:
尝试使用 SVN 时,它失败并显示“拒绝访问:
<scm>
<connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git</connection>
<developerConnection>ssh://[email protected]:10022/somebody/my-project.git</developerConnection>
<url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>
gives me:
给我:
[INFO] Executing: /bin/sh -c cd /home/jra/Documents/git/my-project && git push ssh://[email protected]:10022/somebody my-project-master-1.0.0
....
[ERROR] Access denied.
So, it, again, uses the parent directory.
因此,它再次使用父目录。
How do I force the release plugin to use the real URL I state there?
如何强制发布插件使用我在那里声明的真实 URL?
回答by Romain
As some have said, those workaround can make work the prepare phase of the release but not the perform phase (in my case that was it). I finally managed to have a full release working by finding the correct way to enter the data to put the developperConnection tag :
正如一些人所说,这些解决方法可以使发布的准备阶段工作,但不是执行阶段(在我的情况下就是这样)。我终于找到了正确的方法来输入数据以放置 developerConnection 标签,从而使完整的版本正常工作:
<scm>
<developerConnection>scm:git:[email protected]:groupProject/project.git</developerConnection>
<tag>HEAD</tag>
</scm>
Many other URL format were accepted in my case but in the end failed during the perform or prepare phase of the release (scm:git:ssh://git@gitlab... for instance was having this problem). I don't know if this solution is specific to Gitlab or maybe my project but I spent a lot of time finding this workaround...
在我的情况下,许多其他 URL 格式被接受,但最终在发布的执行或准备阶段失败(scm:git:ssh://git@gitlab...例如遇到了这个问题)。我不知道这个解决方案是否特定于 Gitlab 或者我的项目,但我花了很多时间找到这个解决方法......
回答by rabejens
EDIT: The workaround I proposed here does not work for release:perform
, in fact, I did not find a feasible solution till today. I am now doing the release manually as I will describe below.
编辑:我在这里提出的解决方法不适用于release:perform
,事实上,直到今天我才找到可行的解决方案。我现在正在手动发布,我将在下面描述。
I investigated on this issue some more and I think it is a bug. I filed a JIRA for it: MRELEASE-900
我对这个问题进行了更多调查,我认为这是一个错误。我为它提交了 JIRA:MRELEASE-900
I dumped maven-release-plugin
and am now doing the release manually the following way (example: release 1.3.0, snapshot version is 1.3.0-SNAPSHOT):
我转储了maven-release-plugin
,现在正在通过以下方式手动发布(例如:发布 1.3.0,快照版本是 1.3.0-SNAPSHOT):
git checkout master && git pull
just to be suregit checkout -b release-1.3 && git push -u origin release-1.3
cd path/to/my/master/project
mvn versions:set
, it asks me to specify the new version for1.3.0-SNAPSHOT
, I enter1.3.0
git commit -a
so the new version is checked-ingit tag release-1.3.0
git push && git push --tags
- At this point, there is a tagrelease-1.3.0
in the branchrelease-1.3
where all relevant POM version numbers are1.3.0
git checkout master
git merge release-1.3
- do not commit yet, I first update the versions.mvn versions:set
, set new SNAPSHOT version, as per my convention, this would be1.4.0-SNAPSHOT
git commit -a
git push
git checkout master && git pull
只是要确定git checkout -b release-1.3 && git push -u origin release-1.3
cd path/to/my/master/project
mvn versions:set
,它要求我为 指定新版本1.3.0-SNAPSHOT
,我输入1.3.0
git commit -a
所以新版本被签入git tag release-1.3.0
git push && git push --tags
- 此时,所有相关POM版本号所在release-1.3.0
的分支release-1.3
中有一个标签1.3.0
git checkout master
git merge release-1.3
- 还没有提交,我首先更新版本。mvn versions:set
,按照我的惯例,设置新的 SNAPSHOT 版本,这将是1.4.0-SNAPSHOT
git commit -a
git push
I can then create a Jenkins job or what I like on the tag release-1.3.0
to process the release.
然后我可以在标签上创建一个 Jenkins 工作或我喜欢的内容release-1.3.0
来处理发布。
-- Old answer for reference below --
-- 以下旧答案供参考 --
After poking around and trying various things, I made some progress: I have to let the maven-release-plugin think that my-project.git
is a directory and add a faux file to the URL.
在摸索并尝试了各种事情之后,我取得了一些进展:我必须让 maven-release-plugin 认为这my-project.git
是一个目录,并向 URL 添加一个虚假文件。
The following works:
以下工作:
<scm>
<connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</connection>
<developerConnection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</developerConnection>
<url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>
And the same with tSSH:
与 tSSH 相同:
<scm>
<connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</connection>
<developerConnection>ssh://[email protected]:10022/somebody/my-project.git/.git</developerConnection>
<url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>
Now release:prepare
works, but release:perform
fails because it wants to download from ssh://[email protected]:10022/somebody/my-project.git/.git
.
现在release:prepare
工作,但release:perform
失败,因为它想从ssh://[email protected]:10022/somebody/my-project.git/.git
.
回答by OkieOth
I ran in the same issue with a call like that
我用这样的电话遇到了同样的问题
mvn deploy scm:tag
I'm using a gitlab installation and it also don't allow calls like this
我正在使用 gitlab 安装,它也不允许这样的调用
[INFO] Executing: /bin/sh -c cd /home/user/prog/gitlab/test-user_server && git tag -F /tmp/maven-scm-482134407.commit test-user_server-1.1-SNAPSHOT
[INFO] Working directory: /home/user/prog/gitlab/test-user_server
[INFO] Executing: /bin/sh -c cd /home/user/prog/gitlab/test-user_server && git push [email protected]:testplus/test-user_server.git refs/tags/test-user_server-1.1-SNAPSHOT
[INFO] Working directory: /home/user/prog/gitlab/test-user_server
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] Permission denied, please try again.
The problem is this call
问题是这个电话
/bin/sh -c cd /home/user/prog/gitlab/test-user_server && git push [email protected]:testplus/test-user_server.git refs/tags/test-user_server-1.1-SNAPSHOT
But this call is not really necessary, because I start the mvn in the root of my git repository. Instead a command line call like the one below works.
但是这个调用并不是真正必要的,因为我在我的 git 存储库的根目录中启动了 mvn。相反,像下面这样的命令行调用有效。
git push origin refs/tags/test-user_server-1.1-SNAPSHOT
git push origin refs/tags/test-user_server-1.1-SNAPSHOT
So I modified my scm configuration inside my pom.xml to a string like the following and it works for me like a charm.
所以我将 pom.xml 中的 scm 配置修改为如下所示的字符串,它对我来说就像一个魅力。
<scm>
<developerConnection>scm:git:origin</developerConnection>
</scm>
I develop under a Linux OS and so I have not tested if it works also on Windows system.
我在 Linux 操作系统下开发,所以我没有测试它是否也适用于 Windows 系统。
回答by Pere BG
I have the same issue, in my case the plugin pushes to remote the pom updated with the correct version but when is trying to generate the tag it fails because it tries to push the tag to the parent directory.
我有同样的问题,在我的情况下,插件推送到远程使用正确版本更新的 pom 但是当尝试生成标签时它失败了,因为它试图将标签推送到父目录。
Push to master the pom updated with the correct version
推送掌握使用正确版本更新的 pom
git push git@myGitLabURL:parent/project.git refs/heads/master:refs/heads/master
but when it tries to push the tag
但是当它试图推送标签时
push git@myGitLabURL:parent refs/tags/v1.46
Have someone solved it?
有人解决了吗?
回答by PGP
On windows 10 if using gitlab, the scm section might look like (for example):
在 Windows 10 上,如果使用 gitlab,则 scm 部分可能如下所示(例如):
<scm>
<url>https://gitlab.yourdomain.com/yourproject</url>
<connection>scm:git:https://gitlab.yourdomain.com/yourproject.git</connection>
<developerConnection>scm:git:https://gitlab.yourdomain.com/yourproject.git</developerConnection>
<tag>HEAD</tag>
</scm>
Supplying the user name and password in the mvn
command line (below) gets around maven-on-Windows10 failures in running shell prompt-scripts or errors reading user-name:
在mvn
命令行(如下)中提供用户名和密码可以解决 maven-on-Windows10 在运行 shell 提示脚本或读取用户名时出错的问题:
mvn release:clean release:prepare?-Dusername=someUserName -Dpassword=somePassword
BUT: If you need to supply non-standard characters in your username and password (e.g. [email protected]
and some#pwd!
respectivley) then you will need to use URL-encoding on the command line as follows:
但是:如果您需要在您的用户名和密码中提供非标准字符(例如[email protected]
和some#pwd!
相应的字符),那么您将需要在命令行上使用 URL 编码,如下所示:
mvn release:clean release:prepare -Dusername=fred%40somedomain.com -Dpassword=some%23pwd%21