1、希望效果
2、安装插件
3、jenkins - web端设置参数化过程
# def gettags = ['/bin/bash', '-c', "/scripts/shell/front_build_image_deploy/get_image_list.sh '${serviceName} ' alpha"].execute()
# return gettags.text.readLines()
4、脚本内容
#输出需要对服务进行的操作 [root@jenkins ~]# ll /scripts/shell/online_build_image/get_image_list.sh
-rwxr-xr-x 1 root root 121 Jan 20 14:10 /scripts/shell/online_build_image/get_image_list.sh [root@jenkins ~]# cat /scripts/shell/online_build_image/get_image_list.sh #!/bin/sh user=`whoami` #serviceNameLower=`echo es-provider-auth|tr 'A-Z' 'a-z'` serviceName=$1 serviceNameLower=`echo "$serviceName"|tr 'A-Z' 'a-z'` #部署环境(dev,alpha,beta,pro) deploymentEnv=$2 function Usage(){ if [[ "$serviceName" == '' ]];then echo "sh $0 '服务名' '部署环境'" && exit 4 fi } function root_get_image_list(){ if [[ "$deploymentEnv" == 'alpha' ]];then imageName=registry-test.com/wx-k8s/"$serviceNameLower" docker images|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'dev' ]];then imageName=registry-test.com/wx-k8s-dev-alpha-beta/"$deploymentEnv"-"$serviceNameLower" docker images|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'beta' ]];then imageName=registry-test.com/wx-k8s-dev-alpha-beta/"$deploymentEnv"-"$serviceNameLower" docker images|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'pro' ]];then imageName=registry-test.com/wx-k8s-pro/"$serviceNameLower" docker images|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn fi } function jenkis_get_image_list(){ if [[ "$deploymentEnv" == 'alpha' ]];then imageName=registry-test.com/wx-k8s/"$serviceNameLower" ssh root@192.168.56.207 "docker images"|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'dev' ]];then imageName=registry-test.com/wx-k8s-dev-alpha-beta/"$deploymentEnv"-"$serviceNameLower" ssh root@192.168.56.207 "docker images"|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'beta' ]];then imageName=registry-test.com/wx-k8s-dev-alpha-beta/"$deploymentEnv"-"$serviceNameLower" ssh root@192.168.56.207 "docker images"|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn elif [[ "$deploymentEnv" == 'pro' ]];then imageName=registry-test.com/wx-k8s-pro/"$serviceNameLower" ssh root@192.168.56.207 "docker images"|grep "$imageName "|awk '{print $1":"$2" 镜像ID~"$3}'|sort -rn fi } if [[ "$user" == 'root' ]];then Usage root_get_image_list elif [[ "$user" == 'wx' ]];then Usage jenkis_get_image_list fi #注释: build脚本忽略