1

It seems that the TeamCity parameter ${build.counter} is not resolving in our ant build.xml. We have:

<replaceregexp 
        file="AndroidManifest.xml"
        match='android:versionCode="(.*)"'
        replace='android:versionCode="${build.counter}"'
/>

This throws the error:

String types not allowed (at 'versionCode' with value '${build.counter}')

It looks like it is taking the parameter "${build.counter}" as a literal string.

Using another TeamCity integer parameter in place of ${build.counter}, for example ${teamcity.build.id}, works fine.

Does anyone know why this might be?

Update

Thanks Biswajit_86 for the answer. Here also is my related discussion with JetBrains:

Chris Wallis
  • 1,263
  • 8
  • 20
  • Are you sure that this property resolves at all? Try adding `${build.counter}` right before this step. One random nitpick: your regex replacement doesn't use capture group references, so your match pattern doesn't need parentheses. – CAustin Jul 01 '14 at 17:07
  • @CAustin - You are right! That gives me "Step 2/2] echo ${build.counter}". So why wouldn't this property resolve when the others do? – Chris Wallis Jul 01 '14 at 17:38
  • Well to be honest, I don't really know anything about TeamCity. This is where all your properties are coming from, right? It looks like whichever file is holding these properties is badly formatted, as if it contains `build.counter=Step 2/2] echo ${build.counter}` or something similar to that. – CAustin Jul 01 '14 at 17:42
  • That was the log that was generated by your echo line. TeamCity generates these properties at runtime. – Chris Wallis Jul 01 '14 at 18:07
  • its good ask with Jetbrains, I upvoted. – user3584056 Jul 02 '14 at 14:58

2 Answers2

3

Your build files wont know the value of build.counter at all. They can only read system properties but build.counter is a config parameter.

To do this declare a system parameter named system.BUILD.COUNTER whoose value is %build.counter% and pass this into your target. If you change your abnt build.xml to read ${BUILD.COUNTER}, it will work fine

build parameters section system.BUILD.COUNTER %build.counter%

build xml file

<replaceregexp 
        file="AndroidManifest.xml"
        match='android:versionCode="(.*)"'
        replace='android:versionCode="${BUILD.COUNTER}"'
/>
Biswajit_86
  • 3,661
  • 2
  • 22
  • 36
  • This looks interesting, but what about others like teamcity.build.id and build.number. They resolve fine in build.xml. Is there a difference between them and build.counter? – Chris Wallis Jul 02 '14 at 08:40
  • do you have an example of using build.id. build.number is published both as as system property and an env variable by teamcity – Biswajit_86 Jul 02 '14 at 16:04
0

Ant won't read teamctiy varaibles directly. You'll need to create a similar build.counter property in your ant project like:

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

and pass its value from Teamcity build step like:

enter image description here

Mohammad Nadeem
  • 9,134
  • 14
  • 56
  • 82
  • We need not have to define property build.counter as with which it will set to empty string which will then make not changeble later – user3584056 Jul 02 '14 at 07:48
  • Its value need to be passed from Teamcity in Additional Ant command line parameters which will override the default blank value. – Mohammad Nadeem Jul 02 '14 at 08:25
  • true, but for which property needs to be present with `var` ant-contrib task I think. And to add, if ant command line is not used it can be set to additional custom variable with env variable which could be retrieved in build.xml with ${env.BUILD_COUNTER} – user3584056 Jul 02 '14 at 08:58
  • I mean reset not present – user3584056 Jul 02 '14 at 10:34