Commit c047431e authored by 赵凯's avatar 赵凯 💬

fix pre

parent b4997121
#!/usr/bin/env python3
import sys
import requests,json
from common.token import getToken
def tasks(projectid, env, commitid, info):
def tasks(projectid, env, commitid, info, ref):
cookie = getToken()
url = "https://gw.qimai.shop/api/jenkins/jenkinsjob/tasks/"
# payload="{\"gray\":false,\"eta\":\"\",\"pname\":47,\"env\":\"test\",\"ref\":\"test\",\"info\":\"test 部署, 桌码迁移\",\"commitid\":\"e974fb255fd38020367d0a6ed54949d121ecf548\"}"
payload=f'{{"gray":false,"eta":"","pname":"{projectid}","env":"{env}","ref":"{env}","info":"{info}","commitid":"{commitid}"}}'
payload=f'{{"gray":false,"eta":"","pname":"{projectid}","env":"{env}","ref":"{ref}","info":"{info}","commitid":"{commitid}"}}'
payload=payload.encode("utf-8").decode("latin1")
headers = {
'authority': 'gw.qimai.shop',
......
......@@ -70,7 +70,7 @@ if len(argv) == 1:
else:
env = argv[1]
if env not in ["test","beta","pre","pre-run"]:
if env not in ["test","beta","pre"]:
sys.exit("env环境参数设置错误")
if len(argv) == 2:
......@@ -85,7 +85,7 @@ if env in ['test', 'beta']:
# 是否job服务部署
job = ''
if len(argv) == 4:
if len(argv) >= 4:
isJob = argv[3]
if isJob == '-job':
job = '-job'
......@@ -101,7 +101,7 @@ if len(argv) == 4:
# 指定部署分支
ref = ''
if len(argv) == 5:
if len(argv) >= 5:
ref = argv[4]
......@@ -111,8 +111,15 @@ projectResult = checkProjIdGetResult(job)
projectid = projectResult['id']
# 拉取项目最新任务
rst_results_one = tasksEnv(projectid, env)
if ref == '':
ref = rst_results_one['ref']
# 若是test, beta环境部署, 指定部署分支
# pre环境,则取指定的部署分支
if env in ['test', 'beta']:
ref = env
else:
if ref == '':
ref = rst_results_one['ref']
# opms-pre命令,只会拉取最新环境节点,不会部署
# opms-pre-run命令,才会继续部署
if (not isRun) and (env in ['pre']):
......@@ -128,7 +135,7 @@ projectEnvRef = next((env_ref for env_ref in projectResult['env_ref'] if env_ref
commitidData = checkCommitid(projectid, env, ref)
commitid = commitidData['commitid']
# 创建部署任务
taskid = tasks(projectid, env, commitid, info)
taskid = tasks(projectid, env, commitid, info, ref)
time.sleep(3)
# 执行部署任务 or 执行集群部署任务
multi_zone_deploy = projectEnvRef.get('multi_zone_deploy', False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment