Escaping TeamCity "double quote" variables in property of ANT script

Completed

Hello,

In a TeamCity ANT step/metar-runner, when some property coming from TeamCity variable is containing some double-quote, the build fails with: Element type "property" must be followed by either attribute specifications, ">" or "/>".

Sample with a simple ANT step with this Build file content:
---------------------
<project>
    <property name="param" value="%env.TEAMCITY_CAPTURE_ENV%" />
    <echo level="info" message="Value: '${param}'" />
</project>
---------------------
NB: 'env.TEAMCITY_CAPTURE_ENV' is containing some ".

Using $(<property name>) notation seems NOT work.

Is there a way to escape this kind of specific character ?

Many thanks.
Best regards

0
5 comments

Same problem with variable content contains "&" :-(. The error is in this case:

The entity name must immediately follow the '&' in the entity reference.

 

0

Hi Alix,

 

Is there any reason why using the $() notation is not enough for you? As you already linked from our documentation, that's the notation that teamcity expects to be used within ant scripts.

0

Hi Denis,

Thanks for your reply. I have fixed my initial post, because the '$(<property name>)' seems NOT work.

------------
<project>
  <echo level="info" message="Value (with prefix): '$(env.TEAMCITY_CAPTURE_ENV)'" />
  <echo level="info" message="Value (no prefix) : '$(TEAMCITY_CAPTURE_ENV)'" />
</project>
------------

The result is:

=> Seems not interpreted

It is perhaps a misunderstanding from my side :-/.

If this variable reference can work and escapes the ANT "special" characters, it could answer :-).

0

Hi Alix,

 

For some reason there was a typo on our docs about the $() notation, it not being $() but ${} just like in regular Ant. I'm having it fixed in the docs as soon as I can, and I copied it from there without noticing. The ${} notation is the one that should work (provided you have the environment set to "env" such as <property environment="env" />). That deals with all of " and $ just fine, I have thoroughly tested it.

 

Regarding the types of parameters:

-Regular parameters will NOT be passed.

-System parameters will be passed fine (system.TEAMCITY_CAPTURE_ENV) and should be picked up without the prefix (${TEAMCITY_CAPTURE_ENV}

-Env parameters will be passed as env vars, and need to be picked up with the prefix (${env.TEAMCITY_CAPTURE_ENV}) and making sure you have set the environment as discussed above.

1

Hi Denis,

Many thanks for this feedback. ${env.SOME_VAR} (and system) works like a charm.

Unfortunately, my real use case is with regular parameter :-/ (TEAMCITY_CAPTURE_ENV was used because this parameter is existing on all builds and contain a " ).
It is about 'teamcity.pullRequest.title' parameter in a (temporary) ANT script about SonarQube parameters auto-provisioning (see gist). I will be patient and and wait next release of TeamCity.SonarQubePlugin containing #77 for a sustainable solution :-).

Best regards

0

Please sign in to leave a comment.