This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ant, how to do multi-stage command pipe, create file  RSS feed

sam detweiler
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am converting a long time batch file build to using jenkins and ant.. so far all good.

but I have this little problem I just can't seem to find a good solution for..
as part of my build process, I generate a version.txt file that contains content from one of the source files.

here is the batch file version
rem put int he fixed text
echo -n 'version=' >version.txt
rem find the source line 'my $version = "x.yz"'
rem get the number part without the quotes
grep -i 'my $version' $source_file | grep -o -P '(?<=\").+?(?=\")' >>version.txt

so, I grep the file, get the one line, then regex extract just the x.yz part, then append it to the file created in step one.
this gets published along with the install file so that the automated installers can get for my package release level.
(without having to open my tar.gz to read the same file).

so I have tried (echo followed by real exec),
get [exec] grep missing ')'
the echoed data works cut/paste at the common prompt

<echo> "&quot;grep -i &apos;my $version&apos; ${src.file} | grep -o -P &apos;(?&lt;=\&quot;).+?(?=\&")&apos; &gt;&gt; version.txt&quot;"</echo>
<exec executable="sh">
<arg value="-c" />
<arg line="&quot;grep -i &apos;my $version&apos; ${src.file} | grep -o -P &apos;(?&lt;=\&quot;).+?(?=\&quot;)&apos; &gt;&gt; version.txt&quot;"/>

which looks like this after the expansion
"grep -i 'my $version' ${src.file} | grep -o -P '(?<=\").+?(?=\")' >> version.txt"
Peter Johnson
Posts: 5856
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand this correctly, you want to create a new file name version.txt that has the contents:

where <version-nbr> if a value that was plucked out of another file that contains the version number value.

Here is what I would do. First, I would place the version.txt under source control with the following contents:

I would also modify the file that contains the line 'my $version = "x.yz"' to read 'my $version = "${version.nbr}"'.

Then I would pass the desired value for ${version.nbr} to the script (In our builds, we hard-code release number part of the version number and let Jenkins supply the Subversion revision numger for the rest of the version number) and then <copy> both files with the <expandProperties> <filterchain>. The key here is to not embed the version number in any files but to use property values any place you need version numbers, then supply the version number externally, and make Ant replace the version numbers.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!