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…

  • Sending Cppcheck result/report on email from Jenkins using email-ext plugin
  • How can I execute Shell script in Jenkins?
  • Cannot run phploc installed through composer
  • Sonar analysing Maven 3 and multi language project using JENKINS
  • VM Could not reserve enough space for object heap
  • Jenkins seed job that executes only DSL scripts modified since the last run?
  • Run Parts of a Pipeline as Separate Job
  • How can I update Pom.xml files automatically with Git?
  • How to uninstall Jenkins?
  • How to reset build number in jenkins?
  • Hudson/Jenkins Git build all branches
  • Jenkins CLI: using Anonymous permissions instead of the user defined ones
  • 2 Solutions collect form web for “maven picking up environment variable set by jenkins”

    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.

    Git Baby is a git and github fan, let's start git clone.