【问题标题】:Apache Ant stuck while calling git pullApache Ant 在调用 git pull 时卡住了
【发布时间】:2014-10-16 08:11:40
【问题描述】:

在 apache ant 脚本中我有宏:

<macrodef name = "git">
  <attribute name = "command" />
  <attribute name = "options" />
  <attribute name = "dir" default = "" />
  <attribute name="failonerror" default="false"/>
  <sequential>
    <echo message = "GIT Command: git @{command} @{options}, dir: @{dir}" />
    <exec executable = "C:\Git\cmd\git.exe" dir = "@{dir}">
      <arg value = "@{command}" />
      <arg value = "@{options}" />
    </exec>
  </sequential>
</macrodef>

后来我打电话给:

<git command = "pull" options = '-v' dir = "subfolder/subsubfolder" failonerror = "true"/>

但是,当我以 subfolder/subsubfolderC:\direct\path\to\subfolder\subsubfolder\ 的 dir 开始我的 Hudson 工作时,我的工作就卡在上面了,我只能在控制台输出中得到回显。甚至没有错误或任何东西。 Hudson 安装在装有 Windows XP 的机器上。

我尝试在 Windows CMD 中使用此命令 - 当我在 repo 文件夹中时它正在工作,如下所示:

C:\direct\path\to\subfolder\subsubfolder>C:\Git\cmd\git.exe pull -v

我做错了什么?有没有办法更好地将 git 与 ant 集成?

一些新的笔记:

  • 如果我尝试在错误目录中执行 git pull 会出错。
  • 如果我尝试执行 git checkout,它可以工作。
  • 如果我尝试执行 git fetch,它会像 git pull 一样挂起。

另一个编辑,也许是一些线索: 我更改直接 Git 调用 .bat 文件,其中包含 git 命令。很简单一些CD 进入目录然后git pull。当我运行脚本时,它工作得很好。但它永远挂在哈德逊。也许是在 Java 中调用 git subprocess 需要一些环境变量? Git 正在使用 SSH 无电源连接,后台没有任何代理。

【问题讨论】:

    标签: git ant hudson


    【解决方案1】:

    如果它“挂起”,则可能是一个交互式提示,而 Jenkins 无法处理。

    尝试在末尾添加&lt;arg line="&gt; out.txt 2&gt;&amp;1"/&gt; 到您的exec。这会将所有内容重定向到一个文件,以便在它再次挂起后终止作业,并查看该文件的内容out.txt

    请注意,您需要转义 &gt;&amp;,因此它将是:
    &lt;arg line="&amp;gt; out.txt 2&amp;gt;&amp;amp;1"/&gt;

    【讨论】:

    • 我不能简单地通过 &gt; out 2&gt;&amp;1 重定向输出 - 我收到无效的 refspec 错误。 Ant Exec Task 有outputoutputproperty 用于重定向输出。但他们什么也没返回,甚至没有创建文件。无论如何 - 我正在使用与存储库的无电源 SSH 连接。在 Windows CMD 或 GitBash 中使用命令不需要输入任何内容。
    • Jenkins 使用它自己的“jenkins”用户(在 Windows 上,默认情况下它使用“本地系统”用户),这与您通常的登录用户不同。如果您使用无密码 SSH,依赖于您的用户配置文件文件夹中的密钥,那将不适用于 jenkins 会话。您需要特别为 jenkins 用户配置 SSH 密钥,或者更好的是,不要依赖隐含的密钥位置,而是指定密钥的路径。对于ssh,有一个-i 选项。不知道git
    • 非常感谢!你的建议对我帮助很大。作为 Ant 脚本中的临时解决方案,我正在调用 PSExec,它正在调用带有 git 命令的批处理脚本。奇怪,但工作。我将在 Gradle 中重写脚本以简化它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 2012-10-14
    • 2021-11-28
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多