Reputation: 153
I am using NVM to manage my versions of NodeJS. I am trying to integrate it with Maven in a Jenkins job. The following script is executed before Maven runs. I don't think there is a way to pass in the NodeJS installation directory to Maven as an option argument. I believe nvm use
exports the NodeJS installation directory to PATH
, but I could be wrong.
#!/bin/sh -e
source /mounts/dev/jenkins/.nvm/nvm.sh
nvm alias default node
nvm use --delete-prefix v4.2.0 --silent
The reason why Maven needs NodeJS is because of the yeoman-maven-plugin
, which, by default, uses the globally installed version of NodeJS. I know that there is a NodeJS plugin for Jenkins that works, but I don't think using that is optimal.
I think it's possible to integrate NVM into a Jenkins Maven job, but I may be going about it the wrong way. Does anyone have any ideas on a different NVM approach?
Upvotes: 1
Views: 7151
Reputation: 153
Instead of trying to integrate NVM with Maven, we decided to abandon the yeoman-maven-plugin
, and instead went with the frontend-maven-plugin
. The frontend-maven-plugin
allows for local Node and NPM installations, along with other build tools like Gulp and Grunt. The only change that needed to be made was to the pom.xml
. Plus, there is no more need for additional scripting in Jenkins.
Usage example for installing Node and NPM
<plugin>
...
<execution>
<!-- optional: you don't really need execution ids,
but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
<configuration>
<nodeVersion>v0.10.18</nodeVersion>
<npmVersion>1.3.8</npmVersion>
<!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
<downloadRoot>http://myproxy.example.org/nodejs/dist/</downloadRoot>
<!-- optional: where to install node and npm. Defaults to the working directory -->
<installDirectory>target</installDirectory>
</configuration>
</plugin>
More information about the plugin can be found here.
Upvotes: 2