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"
  }
}

 

posted @ 2018-10-08 10:24  BeierWu  阅读(809)  评论(0编辑  收藏  举报