如何使用Jenkins将Node服务器部署到ec2? [英] How to deploy my Node server to ec2 using Jenkins?
问题描述
我可能一直在用这种错误的方式进行搜索...
我有一个Node Express服务器.
I have a Node express server.
我想使用Jenkins将其部署到ec2.
I want to deploy it using Jenkins to ec2.
我有什么选择?
- 如果我想手动上传代码,则使用ssh ...,但我希望它 由詹金斯(Jenkins)完成.
- 是的,服务器位于git存储库上.
- 我想要一个人流
- if I want to upload the code manually, I use ssh... but I want it to be done from Jenkins.
- Yes the server is on a git repo.
- I would like a devops flow
推荐答案
我建议您逐步进行操作:
I recommend you , to do it step by step :
步骤1 :正确配置一个jenkins作业,准备在远程ec2机器上构建您的应用程序.
Step 1 : Configure correctly a jenkins job ready to build your app in remote ec2 machine.
- 在您的jenkins平台上安装此插件:通过SSH插件发布
- 使用此插件在管理Jenkins >>配置系统选项的通过SSH发布部分下添加新的远程服务器.
- 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.
- 现在创建一些詹金斯工作.然后,在构建部分中添加一个名为:通过SSH发送文件或执行命令 的步骤.
- Now create some jenkins job. Then, in build section add a step called : Send files or execute commands over SSH
- 只需选择配置的服务器,然后在 Exec命令部分中输入命令:
- Just select your configured server and enter your commands in Exec command section :
- 对于一个简单的节点js express,此代码可能就足够了,或者只是复制粘贴您现有的代码:
-
仅此而已.只需使用"build"选项进行测试,然后验证您的应用程序是否运行良好.
That is all. Just test with "build" option and verify if your application goes well.
- 将更改推送到git提供程序
- 登录到jenkins并手动执行创建的作业(此步骤已由webhook配置替换)
https://gist.github.com/jrichardsz/38b335f6a5dc8c67a386fd5fb3c6200>
https://gist.github.com/jrichardsz/38b335f6a5dc8c67a386fd5fb3c6200e
这时,此作业已起作用.流程可能是:
At this point, this job is functional. The flow could be :
注意:只有在该步骤没有错误的情况下,您才能从以下步骤开始.
Note: If and only if this step has no errors, you can start with the following step.
步骤2 :通过在git提供程序中配置一个Webhook来实现一个简单的devops流程,当您执行以下操作时,该Webhook会自动触发jenkins作业(在步骤1 中创建) git push .
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
这篇关于如何使用Jenkins将Node服务器部署到ec2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!