|
@@ -79,20 +79,24 @@ class Deployer:
|
|
|
)
|
|
|
current_app.logger.info(self.taskMdl)
|
|
|
|
|
|
+ # 将环境变量包在 "" 里,防止特殊字符报错
|
|
|
+ format_export = lambda val: '"%s"' % str(val).replace('"', '').replace("'", '')
|
|
|
+
|
|
|
self.custom_global_env = {
|
|
|
- 'WEBROOT': str(self.project_info['target_root']),
|
|
|
- 'VERSION': str(self.release_version),
|
|
|
- 'CURRENT_RELEASE': str(self.project_info['target_releases']),
|
|
|
- 'BRANCH': str(self.taskMdl.get('branch')),
|
|
|
- 'TAG': str(self.taskMdl.get('tag')),
|
|
|
- 'COMMIT_ID': str(self.taskMdl.get('commit_id')),
|
|
|
- 'PROJECT_NAME': str(self.project_info['name']).replace('"', '').replace("'", '').replace(" ", '_'),
|
|
|
- 'PROJECT_ID': str(self.project_info['id']),
|
|
|
- 'TASK_NAME': str(self.taskMdl.get('name')).replace('"', '').replace("'", '').replace(" ", '_'),
|
|
|
- 'TASK_ID': str(self.task_id),
|
|
|
- 'DEPLOY_USER': str(self.taskMdl.get('user_name')),
|
|
|
- 'DEPLOY_TIME': str(time.strftime('%Y%m%d-%H:%M:%S', time.localtime(time.time()))),
|
|
|
+ 'WEBROOT': format_export(self.project_info['target_root']),
|
|
|
+ 'VERSION': format_export(self.release_version),
|
|
|
+ 'CURRENT_RELEASE': format_export(self.project_info['target_releases']),
|
|
|
+ 'BRANCH': format_export(self.taskMdl.get('branch')),
|
|
|
+ 'TAG': format_export(self.taskMdl.get('tag')),
|
|
|
+ 'COMMIT_ID': format_export(self.taskMdl.get('commit_id')),
|
|
|
+ 'PROJECT_NAME': format_export(self.project_info['name']),
|
|
|
+ 'PROJECT_ID': format_export(self.project_info['id']),
|
|
|
+ 'TASK_NAME': format_export(self.taskMdl.get('name')),
|
|
|
+ 'TASK_ID': format_export(self.task_id),
|
|
|
+ 'DEPLOY_USER': format_export(self.taskMdl.get('user_name')),
|
|
|
+ 'DEPLOY_TIME': format_export(time.strftime('%Y%m%d-%H:%M:%S', time.localtime(time.time()))),
|
|
|
}
|
|
|
+
|
|
|
if self.project_info['task_vars']:
|
|
|
task_vars = [i.strip() for i in self.project_info['task_vars'].split('\n') if i.strip() and not i.strip().startswith('#')]
|
|
|
for var in task_vars:
|
|
@@ -522,7 +526,7 @@ class Deployer:
|
|
|
waller = Waller(host=host, user=server_info['user'], port=server_info['port'], inline_ssh_env=True)
|
|
|
waller.init_env(env=self.custom_global_env)
|
|
|
|
|
|
- self.connections[host] = waller
|
|
|
+ self.connections[host] = waller
|
|
|
self.prev_release_custom(self.connections[host])
|
|
|
self.release(self.connections[host])
|
|
|
self.post_release(self.connections[host])
|