我建议我们可以使用火箭手 https://i.stack.imgur.com/1pJsF.png对于这个案例。
Here is Rocketeer
我的 Jenkins 服务器上的 NodeJS 应用程序树
$ tree .rocketeer/
.rocketeer/
├── config.php
├── hooks.php
├── logs
│ ├── develop--20170613.log
│ ├── develop--20170614.log
│ ├── develop--20170616.log
│ ├── staging--20180323.log
│ ├── staging--20180324.log
│ ├── staging--20180326.log
│ ├── production--20180223.log
│ ├── production--20180226.log
│ ├── production--20180227.log
│ ├── production--20180227.log
│ └── custom-environment--20180328.log
├── paths.php
├── remote.php
├── scm.php
├── stages.php
└── strategies.php
- 您可以管理 Node JS 应用程序的远程环境:开发、暂存、生产(位于
config.php
file)
- 它将在您的 Gitlab 上提取最新的源代码并保留发布版本,例如
Capistrano
(at remote.php
file)
- 它可以运行你的
pm2 command line
部署最新源代码后(位于hooks.php
file)
- 已经可以帮助运行了
npm install
NodeJS 包。
这是我的 Jenkins 工作设置:
源代码管理
构建触发器
Build
#!/bin/bash -el
cd $JENKINS_HOME/app-deploy/app-socketio
rocketeer deploy --on="develop"
develop意味着连接到开发远程服务器(位于.rocketeer\config.php
file)
'connections' => [
'develop' => [
'host' => '35.xx.xx.xx',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/foo.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'staging' => [
'host' => '34.xx.xx.xx',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/bar.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'production' => [
'host' => '18.xx.xx.xx:63612',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/woot.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'custom-environment' => [
'host' => '13.xx.xx.xx:63612',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/test.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
],
And run pm2
命令行配置在hooks.php
file
'after' => [
'setup' => [],
'deploy' => [
"pm2 delete mynodeproj", //Delete old pm2 task
"pm2 start src/mynodeproj.js", //Start new mynodeproj
],
'cleanup' => [],
],
希望这可以帮到你!!