美文网首页Linux学习|Gentoo/Arch/FreeBSD
用shll脚本让测试环境自动部署

用shll脚本让测试环境自动部署

作者: Java及SpringBoot | 来源:发表于2020-01-20 15:18 被阅读0次

    个人专题目录

    1. 用shll脚本让测试环境自动部署

    #!/usr/bin/env bash
    source /etc/profile
    begin_time=`date "+%Y-%m-%d %H:%M:%S"`
    echo 'begin_time:'${begin_time}
    # 项目git路径
    project_path="/data/projects/demo"
    # 切换到项目路径
    cd ${project_path}
    
    # 获取当前项目的git commitId
    git_commit_id_old=`git log | head -1 | awk -F ' ' '{print $2}'`
    echo 'git_commit_id_old:'${git_commit_id_old}
    
    # 拉取项目更新
    git pull
    
    # 获取拉取后的项目的git commitId
    git_commit_id_new=`git log | head -1 | awk -F ' ' '{print $2}'`
    echo 'git_commit_id_new:'${git_commit_id_new}
    
    # 判断前后是否相等
    if [[ ${git_commit_id_old} != ${git_commit_id_new} ]]
    then
        echo "demo自动部署开始"
        sh /root/deploy.sh
        echo "demo自动部署结束"
    else
        echo "没有变更,跳过自动部署"
    fi
    end_time=`date "+%Y-%m-%d %H:%M:%S"`
    echo 'end_time:'${end_time}
    

    2. shell脚本去解析json数据

    #!/bin/sh
    
    # 淘宝接口,获取IP接口
    retVal=$(curl -s -X GET \
      http://ip.taobao.com/service/getIpInfo.php?ip=63.223.108.42 \
      -H 'cache-control: no-cache')
    echo 'retVal: ' ${retVal}
    
    # {"code":0,"data":{"ip":"63.223.108.42","country":"美国","area":"","region":"华盛顿","city":"西雅图","county":"XX","isp":"电讯盈科","country_id":"US","area_id":"","region_id":"US_147","city_id":"US_1107","county_id":"xx","isp_id":"3000107"}}
    
    echo '{"foo": 42, "bar": "less interesting data"}' | jq .foo
    
    echo ${retVal} | jq .data.ip
    
    country=$(echo ${retVal} | jq .data.country)
    echo 'country: ' ${country}
    

    相关文章

      网友评论

        本文标题:用shll脚本让测试环境自动部署

        本文链接:https://www.haomeiwen.com/subject/ubmjzctx.html