[创建任务]
[Source Code Management - 源码管理]
[安装插件]
# Manage Jenkins 系统设置 -> Manage Plugins 插件管理 -> 构建插件并安装
# Publish over SSH
配置全局工具及插件
maven 安装配置
[maven]
# Jenkins-Maven
: maven integration
: pipeline maven integration
# linux 系统配置信息 (默认安装) | 或者手动解压安装
// 安装路径 : /usr/share/maven
// 仓库路径 : /root/.m2/repository/
# 配置私有仓库等信息
// /usr/share/maven/conf/setting.xml


Publish Over SSH
[Publish Over SSH]
# Send build artifacts over SSH
: Publish Over SSH
# SSH 登录服务器, 拷贝构建产品到目标服务器远程目录, 并执行填入命令
# 凭证配置
// 系统管理 -> 系统配置 -> 搜索 (Publish over SSH)
// 新增并添加相关参数


node 插件
[node]
# NodeJS Plugin executes NodeJS script as a build step.
: NodeJS
# 服务器安装node
# Jenkins 配置 NodeJS
[gulpfile.js]
: npm install -g yarn
: npm install -g gulp
let gulp = require('gulp')
let GulpSSH = require('gulp-ssh')
console.log('您将要部署的服务器是:', 'xx.xx.xx.xx')
// 打开ssh通道
let gulpSSH = new GulpSSH({
ignoreErrors: false,
sshConfig: {
host: 'xx.xx.xx.xx',
port: 22,
username: 'root',
password: 'xxxx',
},
})
gulp.task('execSSH', () => {
return gulpSSH.shell(
'rm -rf xxxx/nodex/*',
{ filePath: 'commands.log' }
)
.pipe(gulp.dest('logs'))
})
// 上传文件
gulp.task('deploy', ['execSSH'], () => {
return gulp
.src(['./dist/**'])
.pipe(gulpSSH.dest('/xx/nodex'))
})
[执行命令未知, jenkins 无法获取环境变量]
#!/bin/bash
source ~/.bash_profile
source /etc/profile




配置全局凭证


项目配置