jenkins构建docker镜像推至远程镜像仓库阿里云shell命令

#!/bin/sh


DIR="."
COMMITID=$(git rev-parse --short HEAD)

docker build -t drake_spiders:$COMMITID $DIR | tee $DIR/Docker_build_result.log
 
RESULT=$(cat $DIR/Docker_build_result.log | tail -n 1)
 
if [["$RESULT" != *Successfully*]];then
  exit -1
fi

#后面是打tag和push操作
echo '>>> Add tag to the new image'
docker tag drake_spiders:$COMMITID  registry.cn-shanghai.aliyuncs.com/mihoyo-plat/drake_spiders:$COMMITID
 
echo '>>> Start push new image'
docker login --username='plat-cr@mihoyo' registry.cn-shanghai.aliyuncs.com --password='W&JjIs1oygYC8Tnc%?BRPw0F#Rio8Qhk'
docker push registry.cn-shanghai.aliyuncs.com/mihoyo-plat/drake_spiders:$COMMITID
# 删除当前本地镜像
docker rmi drake_spiders:$COMMITID
docker rmi registry.cn-shanghai.aliyuncs.com/mihoyo-plat/drake_spiders:$COMMITID
# 删除停止的容器
if [ "$(docker ps -qf status=exited)" ];then
    docker rm $(docker ps -qf status=exited)
fi
#删除none镜像
dangling=$(docker images -f "dangling=true" -q)
if [ "$dangling" ];then
    docker rmi $dangling
fi

你可能感兴趣的:(jenkins构建docker镜像推至远程镜像仓库阿里云shell命令)