Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy node app to remote host from Jenkins?

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?

like image 577
ace Avatar asked Apr 12 '18 16:04

ace


People also ask

Can I deploy node App in GitHub?

GitHub pages host only static HTML pages. No server side technology is supported, so Node. js applications won't run on GitHub pages.


1 Answers

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.

like image 189
runwuf Avatar answered Sep 27 '22 17:09

runwuf