CI/CD脚本

#!/bin/bash

PROJECT_NAME=$1
SERVICE_STATUS=$2
PUBLISH_TYPE=$3
PACKAGE_VERSION=$4
ROLLBACK_VERSION=$5

#创建打包目录
mkdir /data/nfs/maven-package

cd /data/nfs/maven-package

#拉取项目代码
git clone [email protected]:roucute/${PROJECT_NAME}.git

#maven打包
mvn clean package -Dmaven.test.skip=true

#判断打包的时jar包还是war包,同时将包名该为项目名加版本号
if [ -f '/data/nfs/maven-package/target/*.jar' ]; then
    cp -rp /data/nfs/maven-package/target/*.jar /java-app-package/${PROJECT_NAME}/${PACKAGE_VERSION}.jar
else
    cp -rp /data/nfs/maven-package/target/*.war /java-app-package/${PROJECT_NAME}/${PACKAGE_VERSION}.war
fi

#指定发布方式
if [ ${PUBLISH_TYPE} == publish ]; then
    ansible -i dev-hosts  -m copy -a 'src=/java-app-package/${PROJECT_NAME}/${PACKAGE_VERSION}.[jw]ar dest=/app'
elif [ ${PUBLISH_TYPE} == reback_one ]; then
    REBACK=$(ls /java-app-package/${PROJECT_NAME}/ | sort -n |tail -2|head -1)
    ansible -i dev-hosts  -m copy -a 'src=/java-app-package/${PROJECT_NAME}/${REBACK}.[jw]ar dest=/app'
else
    REBACK=$(ls /java-app-package/${PROJECT_NAME}/ | sort -n |tail -3|head -1)
    ansible -i dev-hosts  -m copy -a 'src=/java-app-package/${PROJECT_NAME}/${REBACK}.[jw]ar dest=/app'
fi

#指定版本回退
if [ ! -z ${ROLLBACK_VERSION} ]; then
    ansible -i dev-hosts  -m copy -a 'src=/java-app-package/${PROJECT_NAME}/${ROLLBACK_VERSION}.[jw]ar dest=/app'
fi

你可能感兴趣的:(CI/CD脚本)