This is Jenkins file in the root of node app directory:
pipeline {
agent any
triggers {
pollSCM('* * * * *')
}
stages {
stage("deploy") {
steps {
sh "scp"
}
}
}
}
I configured Jenkins to connect to remote gitlab node proj repo to checkout node project along with Jenkinsfile and run the project's Jenkinsfile. This part works fine but what to do now to perform (note that Jenkins server and the server on which node js is running as well as gitlab repo are all remote to each other):
run these commands on remote server on which node app is running
cd ~/mynodeproj
pm2 stop mynodeproj
copy project source files from Jenkins server to remote server where
node app is running
npm install
export NODE_ENV=production
pm2 start mynodeproj
How to achieve this?
Do I need to setup private/public keypair on server running jenkins so that jenkins server can do scp to copy file to remote server running node app?
GitHub pages host only static HTML pages. No server side technology is supported, so Node. js applications won't run on GitHub pages.
You might want to consider doing this with ansible and just call your ansible playbook from: Build -> Execute Shell
https://dzone.com/articles/running-ansible-playbooks-from-jenkins
You can have ansible manage all your remote environments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With