Use of variables with Maven

Hi,

I need to pass a Maven variable that sets a directory full path. I have not been able to get this to work with the Maven build runner.

This works from a command line:
maven clean install -P=integration -DconfigDir=`pwd`/config

I have tried the following in "Additional Maven command line parameters" through the Maven build runner:
-P=integration -DconfigDir=`pwd`/config
or
-P=integration -DconfigDir=%dep.bt4.teamcity.build.default.checkoutDir%/config
or
-P=integration -DconfigDir=%teamcity.build.default.checkoutDir%/config

In each case, the maven-based TeamCity build cannot find the file in the target directory and fails.

How can I set the checkout directory as a variable in a maven parameter?

Thanks,
-Dave

6 comments
Comment actions Permalink

Dave,

According to documentaiton, property is called teamcity.build.checkoutDir

Please, give it a try.

0
Comment actions Permalink

Hi Nikita,

I tried the variable that you suggested but the result was the same - the build failed in the same way.
Should the variable be called this way?: %teamcity.build.checkoutDir%

Thanks,
-Dave

0
Comment actions Permalink

Dave,

You have to put following value to "Additional Maven command line parameters" field:

-P=integration -DconfigDir=%teamcity.build.checkoutDir%/config

after that, configDir will contain full path to checkout dir plus "/config".

In case, your build still fails, please add "-X' parameter to the field, re-run the build and attach resulting build log to this forum thread.

0
Comment actions Permalink

The variable + config dir name for the configDir value that you suggested is what I had tried. I was never able to make the TeamCity variables work.

Instead the following workaround was successful:
- Externalized the required properties file outside of source code.
- Set configDir to an explicit path.
- Also had to remove all quotes around maven argument values as they seem to be used literally by TeamCity.

So, I never got TeamCity variables to work with my maven build but the build is now working.

-Dave

0
Comment actions Permalink

Dave,

Please attach the build log for failing build with "-P=integration -DconfigDir=%teamcity.build.checkoutDir%/config"  settings.

0
Comment actions Permalink

NSkvortsov wrote:

Dave,

Please attach the build log for failing build with "-P=integration -DconfigDir=%teamcity.build.checkoutDir%/config"  settings.


I tried it again and it worked using the TeamCity variable included in the configDir value. I had given you a very simplified version of the maven command that we use. There are actually many additional arguments. I think the problem was that I had wrapped first all then some of the maven arguments values in double quotes. Quotes around maven variables works fine when running maven from the command line but it seems that TeamCity takes the quotes literally. Once I removed all quotes, it worked.

So, it works now using a source code properties file which is preferable to using an external file on each TeamCity agent. Thanks, Nikita!

-Dave

0

Please sign in to leave a comment.