git-log 错误:参数'master'不明确



我正在运行存储在git仓库中的java项目的maven构建。当发布计划在构建服务器上运行时(使用Bamboo),它会发出以下git命令:

git log -n1 --date-order master

却收到以下错误:

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
当然,我有一个主分支,当我拉下repo并在本地运行命令时,它工作得很好。我的猜测是构建服务器上有不同的配置,但我不知道该找什么。我希望你们中有一个it专家能有一些见解。

作为参考,这里是我从maven构建中获得的实际错误日志。它发生在buildnumber-maven-plugin执行期间:

build   19-Aug-2015 15:10:28    [INFO] [INFO] --- buildnumber-maven-plugin:1.2:create (default) @ my-rest-project ---
build   19-Aug-2015 15:10:28    [INFO] [INFO] Verifying there are no local modifications ...
build   19-Aug-2015 15:10:28    [INFO] [INFO] Executing: /bin/sh -c cd /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout && git status --porcelain
build   19-Aug-2015 15:10:28    [INFO] [INFO] Working directory: /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout
build   19-Aug-2015 15:10:28    [INFO] [INFO] Executing: /bin/sh -c cd /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout && git log -n1 --date-order master
build   19-Aug-2015 15:10:28    [INFO] [INFO] Working directory: /usr/local/atlassian/bamboo-home/xml-data/build-dir/MKL-RR-JOB1/target/checkout
build   19-Aug-2015 15:10:28    [INFO] [ERROR] Provider message:
build   19-Aug-2015 15:10:28    [INFO] [ERROR] The git-log command failed.
build   19-Aug-2015 15:10:28    [INFO] [ERROR] Command output:
build   19-Aug-2015 15:10:28    [INFO] [ERROR] fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
build   19-Aug-2015 15:10:28    [INFO] Use '--' to separate paths from revisions, like this:
build   19-Aug-2015 15:10:28    [INFO] 'git <command> [<revision>...] -- [<file>...]'

fatal: ambiguous argument 'master':未知的版本或路径不在工作树中。

这似乎是git版本问题,在我们的CI机上运行的git命令(或包)与buildnumer-maven-plugin生成的命令不兼容。它在我的Mac本地运行。

是什么固定它在我们的CI盒是改变doUpdatefalse。我们已经将doCheck设置为false,所以现在我们的配置看起来像:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    ...
    <configuration>
        <doCheck>false</doCheck>
        <doUpdate>false</doUpdate>  <!-- changed this from true -->
    </configuration>
</plugin>

这会导致buildnumber-maven-plugin发出以下git命令,该命令似乎在任何地方都能正常工作:

[INFO] --- buildnumber-maven-plugin:1.4:create (default) @ parent ---
[INFO] Executing: /bin/sh -c cd '/build/parent' && 'git' 'rev-parse' '--verify' 'HEAD'

运行maven-release-plugin 2.2及以下版本时有效。

事实证明,当发布插件的版本介于2.3-2.5之间时,maven-release-plugin和maven-buildnumber-plugin之间存在某种冲突(截至撰写本文时,最新版本为2.5)。

我不确定错误的确切原因是什么,但是日志显示release-plugin在这些版本中执行了额外的git命令,并且不知何故导致在它之后运行的buildnumber插件失败。

具体来说,它运行git ls-remote ssh://git@reponame.git并在一个临时目录中运行,而不是在所有其他git命令运行的目录中运行。我不确定这是Maven的故障还是Bamboo的故障。无论如何,我现在知道如何解决它了。

更新:在遇到另一个bamboo/maven-release/git问题迫使我将maven-release-plugin升级到2.5之后,我决定解决所有这些问题的唯一方法就是放弃buildnumber插件。最终是buildnumber插件导致了这个问题,毕竟它对我的工作流程并不重要。

构建服务器可能只有来自您的而不是git存储库的文件。在许多构建服务器中,这是一个非常常见的设置,您可能需要检查是否存在这种情况。

许多构建服务器也提供了一个选项来检查repo

最新更新