jenkins脚本执行示例:
//环境定义与
cd $WORKSPACE
module=news-user
cd $module/
case $deploy in
deploy) //发布模块
//编译
/opt/gradle/bin/gradle clean
/opt/gradle/bin/gradle bootRepackage
//打包
docker build -t reg.***.com/news-qa/$module:$BUILD_NUMBER .
//上传镜像库
docker login -u*** -p*** reg.***.com
docker push reg.***.com/news-qa/$module:$BUILD_NUMBER
//清除打包镜像
docker rmi --force `docker images |grep $module|awk '{print $3}'`
//登录rancher 集群并切换至需要更新的项目
/usr/local/bin/rancher login https://ranchertest.****.com/v3 --token token-zj759:****** --context c-cmfdk:p-htkzp
//更新指定的POD
/usr/local/bin/rancher kubectl set image deploy $module $module=reg.***.com/news-qa/$module:$BUILD_NUMBER -n news-qa1
;;
//回滚
rollback)
echo "rollback"
echo "rollback version:$version"
//回滚至指定的版本
/usr/local/bin/rancher login https://ranchertest.****.com/v3 --token token-zj759:****** --context c-cmfdk:p-htkzp
/usr/local/bin/rancher kubectl set image deploy $module $module=reg.*****.com/news-qa/$module:$version -n news-qa1
;;
*)
exit
;;
esac