【问题标题】:Why does this macrodef fail?为什么这个宏定义失败?
【发布时间】:2013-12-02 10:41:30
【问题描述】:

我正在尝试为构建 xml 中的每个目标打印一个本地时间戳。我有这个宏定义来尝试解决每次打印的相同时间戳。

<macrodef name="timestamp.echo"> 
    <attribute name="message"/> 
        <sequential> 
            <local name="current.time" />
                <tstamp> 
                    <format property="current.time" pattern="dd/MM/yyyy hh:mm:ss.SSS"/> 
                </tstamp> 
                    <echo message="${current.time}@{message}" />
        </sequential> 
</macrodef>

这段代码位于每个目标的末尾,但在目标内 -

<timestamp.echo message="Mail sent" />

当我在本地任务上运行它时,它运行良好,但是当我使用 Jenkins 运行时它失败了。我收到此错误消息 -

Problem: failed to create task or type local
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

我很挣扎,因为我已经声明了名称,但看不到问题的原因。任何帮助表示赞赏。

未来参考答案

对于早期的 Ant 版本,我发现这将完成创建本地时间戳的工作 -

<target name="timestamp">
  <tstamp>
    <format property="current.time" pattern="MM/dd/yyyy hh:mm:ss.SSS" />
  </tstamp>
  <echo message="${current.time} ${message}" />      
</target>

然后将其插入目标中即可 -

      <antcall target="timestamp">
        <param name="message" value="Completed" />
      </antcall>

【问题讨论】:

    标签: ant build jenkins


    【解决方案1】:

    &lt;local&gt; 任务已添加到 version 1.8 中的 Ant。将 Ant 至少升级到 1.8 或更高版本。

    否则,您可能不得不使用第三方 Ant-Contrib 的 &lt;var&gt; task 来模拟作用域属性。

    【讨论】:

    • 这是正确的答案,不幸的是我被告知升级是不可能的,所以我会调查从这里去哪里。
    • 谢谢。我挣扎了一个小时。你的回答有帮助。
    猜你喜欢
    • 2017-09-08
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多