1

I'm trying to add the buildnumber maven plugin to include the hgchangeset from mercurial. This works great for me when running in the Terminal (I'm on Mac OSX).

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.2</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>create</goal>
          <goal>hgchangeset</goal>  // The specific goal I'm interested in
          <goal>create-timestamp</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <doCheck>false</doCheck>
      <doUpdate>false</doUpdate>
      <revisionOnScmFailure>true</revisionOnScmFailure>
      <!-- format of the property 'buildNumber' -->
      <format>{0,date,MMdd-HHmm}</format>
      <items>
        <item>timestamp</item>
      </items>
    </configuration>
  </plugin>
</plugins>

However, when running in Eclipse and Jenkins, I get this error:

[INFO] EXECUTING: /bin/sh -c cd /Users/Shared/Jenkins/Home/jobs/proj/workspace && hg id -i
[ERROR] 
EXECUTION FAILED
  Execution of cmd : id failed with exit code: 127.
  Working directory was: 
    /Users/Shared/Jenkins/Home/jobs/proj/workspace
  Your Hg installation seems to be valid and complete.
    Hg version: NA (OK)

Logging into that server as the user 'jenkins', I can execute: hg id -i just fine and I see the correct output, as the hg binary is on my $PATH and that's recognized in the console.

Similarly, Eclipse gives the same output. I imagine this is because in Terminal the maven build can see my hg binary in /usr/local/bin but Eclipse and Jenkins cannot.

Is there any way I can tell Maven to use hg at that location? I don't care if it has to be hardcoded since the binary location is the same on all our computers.

Thanks in advance

echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin

Peter Mularien
  • 2,578
  • 1
  • 25
  • 34
Cuga
  • 17,668
  • 31
  • 111
  • 166

2 Answers2

1

Looking at the code of the buildnumber-maven-plugin, it seems that there's no way to provide a prefix to the hg executable, or to override the actual command line that's built.

Therefore, I'd suggest modifying the Jenkins build agent configuration so that you adjust the PATH used to locate hg. You can do this following the instructions at Jenkins Distributed Builds setup - typically (depending on how your build slaves are set up), you have a couple options:

  • Modify the launch-slave shell script
  • Modify the .profile (or equivalent) for the user running the build slave
  • Modify the agent configuration in the Jenkins UI, which allows for passing environment variables to the build agent

Any of these should allow you to adjust the contents of the PATH used by the build agent.

Good luck!

Peter Mularien
  • 2,578
  • 1
  • 25
  • 34
0

I encountered the same issue with eclipse and maven - Though my terminal reported a $PATH that included the path of the binary, the maven-plugin in eclipse was not finding it.

I soon realized the problem: Eclipse had been started from the UI and not the terminal, so it did not inherit the environment variables from the terminal, which includes $PATH. This can be quickly tested by starting eclipse from the terminal

$./eclipse

Now, the maven in this instance of eclipse was able to find the binary alright.

In order to get the path into eclipse when it is started from the UI, you will need to add the path to /etc/paths also