Search code examples
node.jspowershellnpmoctopus-deploy

Run npm command during post deploy powershell step in Octopus


I have a nodejs application that I've built/packaged via teamcity as well as deploy to one of our servers (which has node installed) through the Octopus deploy portal. Everything works ok until i come to the post deploy powershell script from within octopus.

In one of the code blocks I have npm commands that throws an error npm not recognised.When I run the power-shell scripts on the server, everything works but when I try to run this via the octopus post deploy script I get the error as stated above.

I know that node /npm are installed and that the environment variables re:nodejs is set correctly, unless there is something else i'm missing , it still isn't working.

a simple pseudo-code of what i'm trying to do is this:

$deploymentDir = 'D:\Apps\<appname>\<octopus-version-number>' 
    $name = "service" 
    cd $deploymentDir
    if($name){
         Write-Host "link node-windows..."
         npm link node-windows //node-windows is installed globally



    }

else{

    } 

Unless there is something I'm missing , how can I get this to run via octopus ?


Solution

  • There is a possibility that Octopus master/tentacle service runs on different user, check the environment variable for that user also.

    If you unable to find the root cause, the alternate is define one Target scoped variable called "npmPath" ( value may be different based on target ) in octopus to store npm path

    Now, you can use $npmPath variable in script.