4

I would like to use a property, which I defined inside my pom.xml. Now I would like to refer to this property value inside my TeamCity Build Step.

At the moment I'm only able to refer the other way around to use a TeamCity property inside Maven.

In particular I want to do a SSH Deployer with a target like url/path/%maven.output.type%/something with

<properties>
    <!-- Art der Entwicklung -->
    <output.type>testing</output.type>
</properties>

What I tried was to define a parameter in TeamCity but I have no idea how to define the value of this parameter.

Is there any way to use this property inside the TeamCity build?

FaltFe
  • 195
  • 11

1 Answers1

1

You can run a script that will set a teamcity parameter that you can use in a another build step. Here are the build configuration settings I use:

Create a configuration parameter with an empty text value with a name used in the next step (e.g. outputType).

Add a build step, with runner type Command line:

  • Select to run a custom script.

  • In the custom script field, enter a script that will extract the value from the pom file, and tell teamcity to set it in the parameter. For example:

    testing=sed -n 's:.*<output\.type>\(.*\)</output\.type>.*:\1:p' pom.xml

    echo "##teamcity[setParameter name='outputType' value='$testing']"

This will set the teamcity parameter outputType with the value of an element named output.type found in the current project pom file.

In another build step, you can use that parameter in a field like, for instance, the target field:

somepath/%outputType%
CMont
  • 690
  • 6
  • 13
  • This is an interesting approach. I forgot to mention that I was forced to use only one build step. Later we decided to use diffrent maven profiles to change the properties. – FaltFe Apr 14 '17 at 10:30