Вопрос

My aim is to fill property with output of command "git describe". I have a property:

<property name="build.version" value = ""/>

And I want to fill it with output of the following command: git describe

I tried:

<exec program='${git.executable}' outputproperty='build.version'>
  <arg value='describe' />
</exec>

but unlike the Ant, NAnt doesn't support outputproperty :( only output (to file).

Это было полезно?

Решение

You're right. You have resultproperty attribute to hold the exit code and output attribute to redirect the output.

Why don't you redirect the output and load the file afterwards via loadfile task:

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />
</target>

Другие советы

Using trim, you can get rid of the carriage return character at the end. For instance, in the example above, add a line at the end to trim the string

<target name="foo">
  <property
    name="git.output.file"
    value="C:\foo.txt" />
  <exec program="${git.executable}" output="${git.output.file}">
    <arg value="describe" />
  </exec>
  <loadfile
    file="${git.output.file}"
    property="git.output" />

  <property name="git.ouput.trimmed" value="${string::trim(git.output)}" />

</target>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top