• jenkins动态关联参数(动态获取服务器参数)


    1、希望效果

    2、安装插件

    
    

    Active Choices Plug-in

    
    

    目的:关联参数,能够实现动态选择环境后执行Groovy Script

    
    

    页面插件管理: 系统管理 ——> 插件管理

    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脚本忽略
  • 相关阅读:
    清除浮动的方法
    网页滚动到顶部或底部加载
    任意两个数之间的随机数
    每五个一行
    js放大镜
    HTML5本地存储
    jquery checkbox radio 标签 选中的3种方法
    jquery mouseout mouseover 多次执行
    CentOS6.5安装MySQL5.7(也适合其他版本安装)
    ubuntu下ganglia3.7.2编译安装
  • 原文地址:https://www.cnblogs.com/faithH/p/12658974.html
Copyright © 2020-2023  润新知