Ver código fonte

Merge pull request #809 from meolu/2.0/bugfix/format-export

fix #771 项目名称包含|导致发布失败BUG
walle-web.io 6 anos atrás
pai
commit
d26379d227
1 arquivos alterados com 8 adições e 4 exclusões
  1. 8 4
      walle/service/deployer.py

+ 8 - 4
walle/service/deployer.py

@@ -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')),
+                'BRANCH': format_export(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_NAME': format_export(self.project_info['name']),
                 'PROJECT_ID': str(self.project_info['id']),
-                'TASK_NAME': str(self.taskMdl.get('name')).replace('"', '').replace("'", '').replace(" ", '_'),
+                'TASK_NAME': format_export(self.taskMdl.get('name')),
                 '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()))),
             }
+
             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])