查询所有项目:
http://10.x.x.xx:8888/api/v4/projects
查询指定项目(显示的pid用来查询job):
http://10.x.x.xx:8888/api/v4/projects?search=demoproject
如果存在重名的项目,需要指定namespace:
http://10.x.x.xx:8888/api/v4/projects?simple=true&search=$namespace/$project&search_namespaces=true
shell提取pid:
pid=`cat project.txt | grep -o '[0-9]\+' | awk 'NR==1'`
对于项目存在覆盖字符串的情况,比如存在名字abc和abcde,要查找abc的情况:
pid=`cat project.txt | sed 's/}/\n/g' | grep "$prefixName/$modelName.git" | grep -o '[0-9]\+' | awk 'NR==1'`
查询成功的job(会显示所有的jobid):
http://10.x.x.xxx:8888/api/v4/projects/{pid}/jobs?scope[]=success
shell提取jobid:
jid=`cat jobs.txt | grep -o '[0-9]\+' | awk 'NR==1'`
下载最新的zip:
http://x.x.x.xxx:8888/api/v4/projects/{pid}/jobs/{jobid}/artifacts
python代码:
get_id_cmd = ''' curl --globoff --header "PRIVATE-TOKEN: xxxxx" "http://10.1.1.1:8888/api/v4/projects?search=comp" '''
get_id_cmd = get_id_cmd.replace("comp", gitName)
result = json.loads(os.popen(get_id_cmd).read())
pid = -1
if len(result) == 0:
print("download error")
return False
pid = result[0]['id']
print("get "+compName+" id: "+str(pid))
get_job_cmd = ''' curl --globoff --header "PRIVATE-TOKEN: xxxxxx" "http://10.1.1.1:8888/api/v4/projects/pid/jobs?scope[]=success" '''
get_job_cmd = get_job_cmd.replace("pid",str(pid))
result = json.loads(os.popen(get_job_cmd).read())
jobid = -1
if len(result) == 0:
print("download error")
return False
os.system('rm -rf artifacts && rm -f artifacts.zip')
jobid = result[0]['id']
get_artifact_cmd = ''' curl --output artifacts.zip --header "PRIVATE-TOKEN: xxxxx" "http://10.1.1.1:8888/api/v4/projects/pid/jobs/jobnum/artifacts" '''
get_artifact_cmd = get_artifact_cmd.replace("pid",str(pid))
get_artifact_cmd = get_artifact_cmd.replace("jobnum",str(jobid))
os.system(get_artifact_cmd)
#os.system('unzip artifacts.zip && rm -f *.zip')
print("#####################download finish#####################")
shell代码:
curl --header "PRIVATE-TOKEN: xxxxxxx" "http://10.1.1.1:8888/api/v4/projects?simple=true&search=$prefixName/$modelName&search_namespaces=true">project.txt
#pid=`cat project.txt | grep -o '[0-9]\+' | awk 'NR==1'`
#因为sbi总是找到sbiproxy 需要更复杂的查找逻辑
pid=`cat project.txt | sed 's/}/\n/g' | grep "$prefixName/$modelName.git" | grep -o '[0-9]\+' | awk 'NR==1'`
if [ ! -n "$pid" ];then
echo "can not find project in git"
exit 0;
fi
curl --header "PRIVATE-TOKEN: xxxxxx" "http://10.1.1.1:8888/api/v4/projects/$pid/jobs?scope[]=success">jobs.txt
jid=`cat jobs.txt | grep -o '[0-9]\+' | awk 'NR==1'`
if [ ! -n "$pid" ];then
echo "can not find success job in git for pid: $pid"
exit 0;
fi
curl --output artifacts.zip --header "PRIVATE-TOKEN: xxxxx" "http://10.1.1.1:8888/api/v4/projects/$pid/jobs/$jid/artifacts"
unzip artifacts.zip