当前位置: 动力学知识库 > 问答 > 编程问答 >

maven picking up environment variable set by jenkins

问题描述:

I am using the following maven pom.xml snippet to read a property called BUILD_NUMBER from a file jenkins/version.properties.

 <plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>properties-maven-plugin</artifactId>

<executions>

<execution>

<phase>initialize</phase>

<goals>

<goal>read-project-properties</goal>

</goals>

<configuration>

<files>

<file>${project.parent.basedir}/jenkins/version.properties</file>

</files>

</configuration>

</execution>

</executions>

</plugin>

Jenkins also has an environment variable called $BUILD_NUMBER. I have child pom.xmls which try and use the $BUILD_NUMBER, and it keeps picking up the Jenkins environment variable value for $BUILD_NUMBER instead of the one from jenkins/version.properties. I am just wondering if maven puts values it reads from files into the environment? If so, it looks as though Jenkins is over writing this value...

网友答案:

What makes you think ${project.parent.basedir} evaluates to anything useful?

I'd say your <file> points to a non-existing file, so the properties-maven-plugin does not read any properties, so BUILD_NUMBER is not defined as a property, and ${BUILD_NUMBER} falls back to ${env.BUILD_NUMBER}, which is your Jenkins environment variable.

网友答案:

I changed the BUILD_NUMBER variable to a different name so that it didn't clash with the Jenkins $BUILD_NUMBER environment variable. That seems to have fixed the problem. Thanks for the help - set me on the right track.

分享给朋友:
您可能感兴趣的文章:
随机阅读: