Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Travis CI的yaml键值中的转义连字符_Ruby_Yaml_Travis Ci - Fatal编程技术网

Ruby Travis CI的yaml键值中的转义连字符

Ruby Travis CI的yaml键值中的转义连字符,ruby,yaml,travis-ci,Ruby,Yaml,Travis Ci,尝试使用此处指定的before\u script命令在Travis CI构建中创建测试数据库: 特拉维斯抛出: $ psql -c 'create database authentication-server_test;' -U postgres ERROR: syntax error at or near "-" LINE 1: create database authentication-server_test; 我在谷歌上搜索了一段时间,在想如何摆脱连字符时遇到了麻烦。症结似乎在于我必

尝试使用此处指定的
before\u script
命令在Travis CI构建中创建测试数据库:

特拉维斯抛出:

$ psql -c 'create database authentication-server_test;' -U postgres
ERROR:  syntax error at or near "-"
LINE 1: create database authentication-server_test;
我在谷歌上搜索了一段时间,在想如何摆脱连字符时遇到了麻烦。症结似乎在于我必须包装
createdatabaseauthentication-server\u测试在引号中。请注意,Travis文档中的示例没有连字符


有什么想法吗?

您的问题是此PostgreSQL标识符:

authentication-server_test
before_script:
  - bundle exec rake lint
  - psql -c 'create database "authentication-server_test";' -U postgres
需要引用,以便PostgreSQL不会试图将
-
解释为运算符。标识符用双引号引起来,因此您需要:

"authentication-server_test"
输入数据库。您可以在YAML中转义双引号:

before_script:
  - bundle exec rake lint
  - "psql -c 'create database \"authentication-server_test\";' -U postgres"
或者删除外部双引号(字符串的YAML引号),同时添加内部双引号(用于PostgreSQL标识符):

或者切换到
createdb
关于完全避免问题:

before_script:
  - bundle exec rake lint
  - createdb authentication-server_test -U postgres

只需担心shell和YAML的报价需求(这两种需求在这里都不适用)。

PS我还尝试了
-psql-c“create database authentication-server_test;”-U postgres
谢谢你,伙计!在这件事上我的头撞了一段时间。我以前在postgres中见过双引号问题,但我认为Travis是因为yaml语法而不是postgres引发了问题。我已经验证了你的第一个解决方案是有效的。只是验证第二个。可能不会为第三个而烦恼,因为粗略的谷歌没有在travis文档中显示
createdb
。也许你有链接?是的,第二个也有用。我选择了那个,因为它更整洁。谢谢
createdb
是标准的PostgreSQL命令:。
psql-c
方法很奇怪,因为您有三种不同的东西想要使用双引号(YAML、shell、PostgreSQL),至少
createdb
一种方法只有两个(YAML、shell),而且都不需要引号。
before_script:
  - bundle exec rake lint
  - createdb authentication-server_test -U postgres