作者:Rony通_184_176 | 来源:互联网 | 2022-12-20 19:34
这是节点app目录的根目录中的Jenkins文件:
pipeline {
agent any
triggers {
pollSCM('* * * * *')
}
stages {
stage("deploy") {
steps {
sh "scp"
}
}
}
}
我将Jenkins配置为连接到远程gitlab节点proj repo以与Jenkinsfile一起检出节点项目并运行项目的Jenkinsfile.这部分工作正常,但现在要做什么(注意Jenkins服务器和运行节点js的服务器以及gitlab repo彼此都是远程的):
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
怎么做到这一点?
我是否需要在运行jenkins的服务器上设置私有/公共密钥对,以便jenkins服务器可以执行scp将文件复制到运行节点应用程序的远程服务器?
1> Quỳnh Nguyễn..:
我建议我们可以在这种情况下使用Rocketeer.
这是Rocketeer
我的Jenkins Server for NodeJS App上的树
$ 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
您可以管理NodeJS App的远程环境:开发,分段,生产(在config.php
文件中)
它将在您的Gitlab上提取最新的源代码并保持发布版本Capistrano
(如remote.php
文件)
它可以运行你的pm2 command line
部署后的最新源代码(在hooks.php
文件中)
它已经帮助运行npm install
NodeJS包.
所以这是我的詹金斯工作设置:
源代码管理
构建触发器
建立
#!/bin/bash -el
cd $JENKINS_HOME/app-deploy/app-socketio
rocketeer deploy --on="develop"
开发意味着连接到开发远程服务器(在.rocketeer\config.php
文件中)
'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,
],
],
并pm2
在hooks.php
文件中运行命令行configure
'after' => [
'setup' => [],
'deploy' => [
"pm2 delete mynodeproj", //Delete old pm2 task
"pm2 start src/mynodeproj.js", //Start new mynodeproj
],
'cleanup' => [],
],
希望这可以帮到你!!