• jenkins回滚之groovy动态获取版本号


    grovvy调试:
    部署路径确定下来, 每个服务写死,传参 服务名 + 环境 给版本服务返回版本信息:
    
    groovy取分支:
    def gettags = ("git ls-remote -h git@gitlab.zi.com:crm/zi-crm-app.git").execute()
    gettags.text.readLines().collect { it.split()[1].replaceAll('refs/heads/', '')  }.unique()
    def gettags = ("ls -l").execute()
    gettags.text.readLines().collect { it.split()[1].replaceAll('refs/heads/', '')  }.unique()
    curl baidu.com
    String[] envVars = jenkins.model.Jenkins.getInstance().getGlobalNodeProperties().toMap().collectMany{it.value.getEnvVars().collect{"$it.key=$it.value"}}
    def jobName= manager.getEnvVariable('JOB_BASE_NAME')
    echo -e `curl -s -d "sname=zi-data-dr-test-bk&env=test" 0.0.0.0:8000/version/|tr """ " "`
    
    def gettags = ("curl -s -d "env=zi-data-dr-test-bk,test" 10.11.7.183:8000/version/").execute()
    gettags.text.readLines()
    
    def proc1 = ['/bin/bash', '-c', 'echo -e `curl -s -d "sname=zi-data-dr-test-bk&env=test" 10.11.7.183:8000/version/|tr """ " "`'].execute()
    
    def proc1 = ['/bin/bash', '-c', 'curl -s -d "sname=zi-data-dr-test-bk&env=test" 10.11.7.183:8000/version/'].execute()
    pproc1 = ['echo -e', $proc1].execute()
    def proc2 = ['/bin/bash', '-c', 'echo -e curl -s -d "env=zi-data-dr-test-bk,test" 10.11.7.183:8000/version/|tr """ " "'].execute()
    
    
    # def gettags = ['/bin/bash', '-c', 'curl -s -d "sname=zi-data-dr-test-bk&env=test" 10.11.7.183:8000/version/'].execute()
    # gettags.text.readLines()
    
    Script:
    if (BuildEnv.equals('test')) {
    return ['test']
    } else if (BuildEnv.equals('prod')) {
    return ['prod']
    } else {
    return ['abc']
    }
    Fallback Script: return ['xxx']
    
    def job_name = this.binding.jenkinsProject.name 这个可以获取到 
    
    
    def job_name = this.binding.jenkinsProject.name
    def job_env= this.binding.BuildEnv
    if (BuildEnv.equals('test')) {
    def gettags = ['/bin/bash', '-c', 'curl -s -d "sname=${job_name}&env=${job_env}" 10.11.7.183:8000/version/'].execute()
    return gettags.text.readLines()} 
    if (BuildEnv.equals('develop')) {
    return [job_name,job_env]
    }
  • 相关阅读:
    bootstrap
    Bootstrap面试题
    h5+css3 考试题
    less安装与使用
    css3(四)响应式 Web 设计 - 媒体查询
    css3(三)弹性布局
    css3(三)多列布局
    JavaScriptAPI初识
    Bootstrap面试题
    BS初识
  • 原文地址:https://www.cnblogs.com/yum777/p/11217157.html
Copyright © 2020-2023  润新知