Jenkins将在服务器上实现流程自动化

vdgimpew  于 2023-01-29  发布在  Jenkins
关注(0)|答案(1)|浏览(162)

当前正在服务器上部署应用程序。服务器上项目的结构:

  1. start-switch.json
  2. application_snapshot-001.jar
  3. www.example.com appconfig.properties
  4. workflow.yaml
    1.其他文件夹
    每次有变化,我们必须手动停止服务器(pm2 stop APP_NAME),删除/替换jar文件,并重新启动服务器(pm2 start start-switch.JSON),这是非常麻烦的。
    我想使用Jenkins自动停止服务器,替换从GitHub仓库提取的jar文件,然后重新启动服务器。
    这也有助于在服务器上保留每个展开的版本。
    我如何对Jenkins文件执行这些步骤?
    先谢了。
jtw3ybtb

jtw3ybtb1#

这是一个你可以用Jenkins完成的相当普通的实现。首先,切换到你的项目目录,使用sh停止服务器。然后使用GitSCM plugin拉取你的jar。删除旧的jar,粘贴新的,然后再次使用sh启动服务器。

dir("path/to/proj_dir"){
    sh "pm2 stop APP_NAME"
    sh "rm application_snapshot-001.jar"
    checkout scmGit(
        branches: [[name: 'master']],
        userRemoteConfigs: [[url: '<repo>']])
    sh "mv path/to/new/jar path/to/old/jar application_snapshot-001.jar"
    sh "pm2 start start-switch.JSON"
}

如果您使用的是Windows计算机,则必须使用bat而不是sh

相关问题