jonnyzzz / TeamCity.Node

Node.js, NPM and Phantom.JS runners for TeamCity
Apache License 2.0
309 stars 49 forks source link

Permit use of .nvmrc file to define Node version #52

Open adametry opened 10 years ago

adametry commented 10 years ago

Agents won't run unless a Node version is defined by the Node.js NVM Installer build step. This would allow builds to vary the Node version with the source. This feature is described under NVM Usage.

jonnyzzz commented 10 years ago

How do you plan to use the file? Do you have it in the version control? Or it is a static file that is available on all build agents?

adametry commented 10 years ago

I have an .nvmrc in version control to set up the developer environment. It would be great to have builds adopt it as well. By using .nvmrc, I can migrate my source to node 0.11 (for example) without adjusting the build; I could even run old and new changesets without having figure out what parameters a build step required at the time.

I did try to work around the requirement by defining an empty parameter as a version (i.e., nvm install %empty%), but I had no luck there either.

jonnyzzz commented 10 years ago

I got your point. Thank you. You may try to report a parameter value from the build from a previous build runner

See http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-AddingorChangingaBuildParameter for more details. Please note, you need to have a parameter declaration in the build configuration to make it work

wrumsby commented 8 years ago

An update here, I got the above working by executing a Node.js runner step before calling nvm with the following source code:

var fs = require('fs');
var version = '0.10';
var data;

try {
    data = fs.readFileSync('.nvmrc', 'utf8');
    version = data.replace(/(^[\s]+|[\s]+$)/g, '');;
} catch (e) {
    console.warn(e);
}

console.log("##teamcity[setParameter name='nvm.node.version' value='" + version + "']");

I then set Node.js version in the Node.js NVM Installer step to %nvm.node.version%

Would be nice if this was built into the NVM Installer, but still, this works.

ediblecode commented 4 years ago

Thanks @wrumsby that was useful. I did something similar in bash in a step before the NVM build step, if this helps anyone:

read -r nvmNodeVersion < .nvmrc
echo "Project Node version from .nvmrc is $nvmNodeVersion"
echo "##teamcity[setParameter name='nvm.node.version' value='$nvmNodeVersion']";
zackmoorelba commented 3 years ago

@ediblecode the bash script worked but it would sure be nice if the plugin had this built in