You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
After deploying code to my server using bit bucket scp pipe, I am using another pipeline to run a script to install node modules and start node server but the pipeline results as failed status and shows like
./server-run.sh: line 1: npm: command not found ./server-run.sh: line 2: pm2: command not found
image: node:10.15.3
pipelines:
custom:
test:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
- pipe: atlassian/scp-deploy:0.3.3
variables:
USER: $USER
SERVER: $SERVER
REMOTE_PATH: '/var/www/stockTest/server'
LOCAL_PATH: 'server/*'
server-start:
- step:
caches:
- node
script:
- ssh $USER@$SERVER "cd /var/www/stockTest/server && ./server-run.sh"
server-run.sh
npm i
pm2 start server-start.js --name stockTest
@Madhan follow the steps given below
1> in your server terminal run echo $PATH
this will give below out put /home/ubuntu/.nvm/versions/node/v16.5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
2> Now open nano /etc/environment and paste the path there like given below
PATH="/home/ubuntu/.nvm/versions/node/v16.5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
This will surely solve your problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I am not using nvm, how do i do this? because node and npm are available in system, however it isn't visible in path variable. So what path to add to environment file?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Madhan ,
Based on the output, it looks that npm and pm2 may not be installed on your server.
What output do you get if you execute the following in a terminal on your server?
npm -v
You can check the following links on how to install npm and pm2 on your server if you haven't done so already:
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for responding for my post,I already have npm node and pm2 and i can manually run my code on my server but unable to do that using bitbucket-pipeline.
Any explanation is welcomed and appreciated. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Madhan ,
Can you double-check/confirm whether npm and pm2 start are installed for the same user that you use to ssh to your server from Pipelines? The user stored in the variable $USER. One possibility is that these are installed for a different user on your server.
Can you execute the commands
npm i
pm2 start server-start.js --name stockTest
on your server as $USER ?
If you are connecting to the correct for this purpose user, then I would suggest the following:
In you bitbucket-pipelines.yml file, change the command of the "server-start" custom pipeline, from
- ssh $USER@$SERVER "cd /var/www/stockTest/server && ./server-run.sh"
to
- ssh $USER@$SERVER "cd /var/www/stockTest/server && npm i && pm2 start server-start.js --name stockTest"
then run this custom build and let me know what is the output of the build. This is to check if the problem is with the execution of the script only and whether the commands can be executed this way.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Theodora Boudale ,
Still getting the same output even after changing the script as suggested by you
+ ssh $USER@$SERVER "cd /var/www/stockTest/server && npm i && pm2 start server-start.js --name stockTest"
bash: npm: command not found
even i cross-checked the npm and pm2 on my server for the user as i mentioned in the script.
Kind regards,
Madhan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Madhan,
Do you have a laptop/computer that you can use to test the SSH connection to the same server? That is, generate an SSH key pair in your client machine, add the public key in the authorized_keys on the server and then execute the same SSH command from your client machine and see what output you get.
I would like us to narrow down whether the problem occurs only when connecting via SSH from Pipelines or if the same issue occurs while connecting from another machine as well.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.