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

时间:2022-06-12 16:19:32

 

 

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]
}