zoukankan      html  css  js  c++  java
  • 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脚本忽略
  • 相关阅读:
    Kubernetes实战指南(三十三):都0202了,你还在手写k8s的yaml文件?
    Hadoop学习笔记
    Anaconda、Pycharm的安装与运行和Python环境的搭建
    常用编程软件文件配置(下载安装教程)
    error C2678: 二进制“<”: 没有找到接受“const _Ty”类型的左操作数的运算符
    Java 移位运算、符号位扩展
    c++ 集合操作
    c++ 输入与缓冲区
    python 装饰器
    python global 与 nonlocal
  • 原文地址:https://www.cnblogs.com/faithH/p/12658974.html
Copyright © 2011-2022 走看看