• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

jekines进行批量部署(pipeline流水线模式)

武飞扬头像
The_bobo
帮助5

利用jekines进行批量部署(pipeline流水线模式)

1.新建节点
(1)【Manage Jenkins】–> 【Manage Nodes and Clouds】
(2)填写节点名称及远程工作目录(/mnt)
2.启动节点服务器
(1)安装java环境
(2)下载agent.jar包
(3)在节点服务器将节点明细页面里的命令用nohup方式启动,例如
nohup java -jar agent.jar -jnlpUrl https://jenkins-dev.huafaih.com/computer/节点名/slave-agent.jnlp -workDir “/mnt” &
3.新建item
(1)【jenkins】 -->【新建item】–>【流水线】
(2)填写流水线,保存

pipeline {
  
   agent none
   
   environment { 
       M2_HOME = '/usr/local/apache-maven-3.5.4'
   }

   stages {
       stage('前端打包开始') {
         agent {
             node{
                 label 'xxzh-slave'
                 customWorkspace '/mnt/workspace/manager/web'
             }
         }
         steps {
            // Get some code from a GitHub repository
            git branch: 'master',
            credentialsId: 'git',
            url: 'https://gitlab.test.com/xxzh/test-web.git'
            sh 'npm install --unsafe-perm=true --allow-root'
            sh 'rm -rf ./dist/*'
            sh 'npm run build:stage'
            sh 'rm -rf ../api/manage/src/main/resources/static/app'
            sh 'mkdir -p ../api/manage/src/main/resources/static/app'
            sh 'cp -rf ./dist/* ../api/manage/src/main/resources/static/app'
            echo 'Build success1'
         }
      }

      stage('后台打包开始') {
         agent {
             node{
                 label 'xxzh-slave'
                 customWorkspace '/mnt/workspace/manager/api'
             }
         }
         steps {
            // Get some code from a GitHub repository
            git branch: 'master',
            credentialsId: 'git',
            url: 'https://gitlab.test.com/xxzh/test-manager.git'
            sh '${M2_HOME}/bin/mvn clean compile install -Dmaven.test.skip=true -P test -e'
            
            echo 'Build success2'
         }
      }

      stage('部署开始') {
          
         agent {
             node{
                 label 'xxzh-slave'
             }
         }
         steps {
         		//备份
            // 用ansible命令将节点服务器部署包上传至应用服务器
            sh 'ansible manager -i /mnt/hosts -m copy -a "src=/mnt/workspace/manager/api/manage/target/manage-0.0.1-SNAPSHOT.jar dest=/zhfi/opr/apps/manager"'
            sh 'ansible manager -i /mnt/hosts -m shell -a "systemctl restart manager" '
            echo '部署成功'
         }
      } 
   }
}
学新通

(3)使用ansible
1>下载安装:yum install ansible -y
2>新建ansible配置文件(/mnt目录下新建hosts文件):

[manager]
manager-01 ansible_connection=local
manager-02 ansible_ssh_host=xxx.xxx.xxx.xxx ansible_ssh_user=root ansible_ssh_pass=password

(4)设置开机启动
vim /etc/systemd/system/manager.service

[Unit]
Description=
Documentation=

[Service]
Type=simple
WorkingDirectory=/zhfi/opr/apps/manager
ExecStart=/usr/local/jdk1.8.0_251/bin/java -jar manage-0.0.1-SNAPSHOT.jar

Restart=always
RestartSec=30

#查看进程状态
systemctl status manager
#启动
systemctl restart manager
#修改后要重载
systemctl daemon-reload

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfgihkf
系列文章
更多 icon
同类精品
更多 icon
继续加载