How to deploy my Node server to ec2 using Jenkins?

2019-06-11 07:03发布

问题:

I have probably been Googling this the wrong way...

I have a Node express server.

I want to deploy it using Jenkins to ec2.

What are my options?


  1. if I want to upload the code manually, I use ssh... but I want it to be done from Jenkins.
  2. Yes the server is on a git repo.
  3. I would like a devops flow

回答1:

You'll have to use AWS CodeDeploy jenkins plugin. This apply to any type of code. Node, java etc

See AWS article Setting Up the Jenkins Plugin for AWS CodeDeploy

Jenkins Plugin Github Link



回答2:

I recommend you , to do it step by step :

Step 1 : Configure correctly a jenkins job ready to build your app in remote ec2 machine.

  • Install this plugin in your jenkins platform : Publish Over SSH Plugin
  • Using this plugin add new remote server under Publish over SSH section in Manage Jenkins >> Configure System option.

  • Now create some jenkins job. Then, in build section add a step called : Send files or execute commands over SSH

  • Just select your configured server and enter your commands in Exec command section :

  • For a simple node js express, this code could be enough or just copy-paste your existing code:

https://gist.github.com/jrichardsz/38b335f6a5dc8c67a386fd5fb3c6200e

  • That is all. Just test with "build" option and verify if your application goes well.

  • At this point, this job is functional. The flow could be :

    • push your changes to your git provider
    • login to jenkins and manually execute the created job (this step is replaced with webhook configuration)

Note: If and only if this step has no errors, you can start with the following step.


Step 2 : Implement a simple devops flow by configuring a webhook in your git provider, which automatically triggers the jenkins job (create in step 1) when you perform a git push.

This guide could be help you with the required configurations :

https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks