DevOps之六 shell以及pipeline 命令部署

Posted Beier928

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevOps之六 shell以及pipeline 命令部署相关的知识,希望对你有一定的参考价值。

一 使用shell命启动spring boot 项目

   1. 使用shell停止当前项目

#!/bin/sh

main() {
    clear
    
    pid=`ps -ef|grep xx.jar|grep -v grep|grep -v kill|awk ‘{print $2}‘`

    if [ -n ${pid} ]; then
       echo ‘start Kill Process --->‘
       kill -9 $pid
   
       until [ -n $tempPid ]
       do
          echo ‘Killing Process ... ...‘
          sleep 2
           tempPid=`ps -ef|grep xx.jar|grep -v grep|grep -v kill|awk ‘{print $2}‘`
       done
       echo ‘killed device.jar <---‘
    fi
}

main $1

  

2. 使用shell拷贝替换要启动的Java包

#!/bin/sh

target=/home/robot/device/jar/xx.jar
if [ -f $target ]; then
    rm -rf $target
fi

cp -rf /var/lib/jenkins/workspace/robot-device/target/xx.jar $target

3. 使用shell启动Java包

#!/bin/sh
echo "赋权限"
chmod -R 777 /home/robot/device/jar/xx.jar
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5007 -jar /home/robot/device/jar/xx.jar  

 

#!/bin/sh
nohup sh startup-api.sh>starup-api.log 2>&1 &

二 使用shell以及docker命令 生成镜像

docker build -t haier-robot-alarm:1.0.0 .
docker login -u hollysys -p 1234 hollysys-xian
docker push haier-robot-alarm:1.0.0

 

三 使用pipeline命令发布程序

node{
    
  def mvnHome
  stage(Preparation) {
      // Get some code from a GitHub repository
      git branch: stage, credentialsId: 4ea34875-7eb6-4c8b-b9b2-f437a0aa5fb2, url: http://172.21.46.15/HairRobot/micro-services/zuul.git
   }
   
  stage("build-web"){
        dir(/var/lib/jenkins/workspace/robot-zuul-cd/webroot) {
            //sh "rm -rf /var/lib/jenkins/workspace/robot-zuul-cd/src/main/resources/static/*"
            git branch: stage, credentialsId: 4ea34875-7eb6-4c8b-b9b2-f437a0aa5fb2, url: http://172.21.46.11/HairRobot/robot-management-platform-web.git
            //replace to the target hiacloud API_URL
            sh returnStdout: true, script: ‘‘‘sed -i "s/const baseUrl = ‘http\:\/\/172.21.12.25\:9000‘;/\/\/const baseUrl = ‘http\:\/\/172.21.12.25\:9000‘;/g" src/api/Ajax.js
            sed -i "s/\/\/const baseUrl = process.API_URL;/const baseUrl = process.API_URL;/g" src/api/Ajax.js‘‘‘
            sh "npm install"
            sh "npm run production"
        }
    }
    
  stage(Build) {
      mvnHome = tool M3
      echo "maven home is ${mvnHome}"
      echo "${env.PATH}"
      def JAVA_HOME
      JAVA_HOME= tool JDK1.8
      echo "${JAVA_HOME}"
      env.JAVA_HOME=JAVA_HOME
      sh "pwd"
      sh "‘${mvnHome}/bin/mvn‘ clean package -DskipTests -X" 
  }

  stage(push docker){
      sh "docker build -t haier-robot-zuul:1.0.0 ."
      sh "docker login -u hollysys -p 1234 hollysys-xian"
      sh "docker push haier-robot-zuul:1.0.0"
  }
}

 

以上是关于DevOps之六 shell以及pipeline 命令部署的主要内容,如果未能解决你的问题,请参考以下文章

DevOps 转型之 Pipeline 实践

微服务之六脉神剑 | (贰)为什么谈论微服务时,总是会谈起DevOps?

devops-jenkins-Pipeline基础语法

linux12Devops --> 09Pipeline简介

gitlab pipelines介绍

azure devops 中的 Pipeline 和 Release Pipeline 有啥区别?