【发布时间】: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>
【问题讨论】: