Changing PATH environment variable before calling Maven pom

Answered

I have a situation where the build script developer relied on the PATH variable in a Maven POM.  The problem is that our build agents are -use and I can NOT change the PATH environment variable on the build agent.  I mean it does mutliple builds and 1 build uses an older version of the app that is referenced in the POM.  So I need to dynamically set the PATH variable before the Maven POM is run.  I know I could use an Ant build script or BAT file to modify the PATH and then call Maven directly to run the POM.  However, then you don't get the "Maven Build Info" tab or integration with the maven plugin to deploy your artifacts.  TeamCity thinks it is not a Maven build now because it is either an Ant or BAT build now.  

I looked at build configuration,  I don't see anywhere that I can modify the PATH environment variable.  Is there a way to do this?  I can't imagine other people haven't run into this.

5 comments

Hello,

You can change PATH parameter in the build script, please try something like this: env.PATH=%env.PATH%;<additional path>. Will it work for you?

0

I cannot change it because then it won't work on other machines - they would have to be setup identical to the build environment. Furthermore, Besides it's a Maven POM and I don't think you can change the PATH once it's running - you have to do it before the script or process is run.

Are you suggesting I add a parameter to the build configuration?

0

Yes, you can create build parameter and use it in Maven build step. In this case the parameters on the build agent won't be affected.

0

Yes, I understand that, but does it really change the SYSTEM path for the machine?  

Suppose a maven build script references "xxxxx.exe" but the machine's PATH is not setup to resolve "xxxx.exe".  Now if I add to the env.PATH the directory that "xxxxx.exe" resides will it now be solved when I run the Maven build?

0

No, the SYSTEM path for the machine won't be changed. 

All build parameters starting with "env." prefix are passed into the build's process environment (omitting the prefix). So PATH variable will be available in Maven build step.

0

Please sign in to leave a comment.