1. [创建任务]
  2. [Source Code Management - 源码管理]
  3. [安装插件]
  4. # Manage Jenkins 系统设置 -> Manage Plugins 插件管理 -> 构建插件并安装
  5. # Publish over SSH

配置全局工具及插件

maven 安装配置

  1. [maven]
  2. # Jenkins-Maven
  3. : maven integration
  4. : pipeline maven integration
  5. # linux 系统配置信息 (默认安装) | 或者手动解压安装
  6. // 安装路径 : /usr/share/maven
  7. // 仓库路径 : /root/.m2/repository/
  8. # 配置私有仓库等信息
  9. // /usr/share/maven/conf/setting.xml

image.png

image.png

Publish Over SSH

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

image.png

image.png

node 插件

  1. [node]
  2. # NodeJS Plugin executes NodeJS script as a build step.
  3. : NodeJS
  4. # 服务器安装node
  5. # Jenkins 配置 NodeJS
  6. [gulpfile.js]
  7. : npm install -g yarn
  8. : npm install -g gulp
  9. let gulp = require('gulp')
  10. let GulpSSH = require('gulp-ssh')
  11. console.log('您将要部署的服务器是:', 'xx.xx.xx.xx')
  12. // 打开ssh通道
  13. let gulpSSH = new GulpSSH({
  14. ignoreErrors: false,
  15. sshConfig: {
  16. host: 'xx.xx.xx.xx',
  17. port: 22,
  18. username: 'root',
  19. password: 'xxxx',
  20. },
  21. })
  22. gulp.task('execSSH', () => {
  23. return gulpSSH.shell(
  24. 'rm -rf xxxx/nodex/*',
  25. { filePath: 'commands.log' }
  26. )
  27. .pipe(gulp.dest('logs'))
  28. })
  29. // 上传文件
  30. gulp.task('deploy', ['execSSH'], () => {
  31. return gulp
  32. .src(['./dist/**'])
  33. .pipe(gulpSSH.dest('/xx/nodex'))
  34. })
  35. [执行命令未知, jenkins 无法获取环境变量]
  36. #!/bin/bash
  37. source ~/.bash_profile
  38. source /etc/profile

image.png

image.png

image.png

image.png

配置全局凭证

image.png
image.png

项目配置