ace*_*ace 11 deployment node.js jenkins gitlab
这是节点app目录的根目录中的Jenkins文件:
pipeline {
agent any
triggers {
pollSCM('* * * * *')
}
stages {
stage("deploy") {
steps {
sh "scp"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我将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
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
我是否需要在运行jenkins的服务器上设置私有/公共密钥对,以便jenkins服务器可以执行scp将文件复制到运行节点应用程序的远程服务器?
我建议我们可以在这种情况下使用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
Run Code Online (Sandbox Code Playgroud)
config.php文件中)Capistrano(如remote.php文件)pm2 command line部署后的最新源代码(在hooks.php文件中)npm installNodeJS包.所以这是我的詹金斯工作设置:
源代码管理
构建触发器
建立
#!/bin/bash -el
cd $JENKINS_HOME/app-deploy/app-socketio
rocketeer deploy --on="develop"
Run Code Online (Sandbox Code Playgroud)
开发意味着连接到开发远程服务器(在.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,
],
],
Run Code Online (Sandbox Code Playgroud)
并pm2在hooks.php文件中运行命令行configure
'after' => [
'setup' => [],
'deploy' => [
"pm2 delete mynodeproj", //Delete old pm2 task
"pm2 start src/mynodeproj.js", //Start new mynodeproj
],
'cleanup' => [],
],
Run Code Online (Sandbox Code Playgroud)
希望这可以帮到你!!
现在要执行的操作(请注意,Jenkins 服务器和运行 Node js 的服务器以及 gitlab repo 都是彼此远程的):
这些命令应该位于 Git 存储库的文件部分中,这意味着在管道使用的工作区中签出。
从那里,您可以将该脚本发送到服务器:
sh 'scp -r script user@server:/path/server'
Run Code Online (Sandbox Code Playgroud)
并通过 ssh 执行它,前提是远程用户的私钥/公钥部署在代理上(或通过ssh-agent 插件传递):
sh 'ssh user@server /path/server/script'
Run Code Online (Sandbox Code Playgroud)
不过,正如这里提到的,技巧是 ssh 会话的 PATH 相当有限,如果节点没有安装在标准路径(如 )中,则可能不包括节点/usr/bin。
因此,您可能需要修改脚本以便使用可执行文件的绝对/absolute/path/to/node路径(例如)
| 归档时间: |
|
| 查看次数: |
3687 次 |
| 最近记录: |