簡體   English   中英

在 Travis CI 的 yaml 鍵值中轉義連字符

[英]Escaping hyphen in yaml key value for Travis CI

嘗試使用此處指定的before_script命令在 Travis CI 構建中創建測試數據庫: https : //docs.travis-ci.com/user/database-setup/#using-postgresql-in-your-builds

# .travis.yml

before_script:
  - bundle exec rake lint
  - "psql -c 'create database authentication-server_test;' -U postgres"

language: ruby

services:
  - postgresql

特拉維斯投擲:

$ psql -c 'create database authentication-server_test;' -U postgres
ERROR:  syntax error at or near "-"
LINE 1: create database authentication-server_test;

我已經做了相當多的谷歌搜索,但在弄清楚如何逃避那個連字符時遇到了麻煩。 症結似乎是我必須包裝create database authentication-server_test; 在引號中。 請注意,Travis 文檔中的示例沒有連字符。

有任何想法嗎?

你的問題是這個 PostgreSQL 標識符:

authentication-server_test

需要引用,以便 PostgreSQL 不會嘗試將-解釋為運算符。 標識符用雙引號引起來,因此您需要這樣做:

"authentication-server_test"

進入數據庫。 您可以轉義 YAML 中的雙引號:

before_script:
  - bundle exec rake lint
  - "psql -c 'create database \"authentication-server_test\";' -U postgres"

或刪除外部雙引號(字符串的 YAML 引號),同時添加內部雙引號(用於 PostgreSQL 標識符):

before_script:
  - bundle exec rake lint
  - psql -c 'create database "authentication-server_test";' -U postgres

或切換到createdb關於完全避免這個問題:

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

只需要擔心 shell 和 YAML 的引用需求(這兩者都不適用於這里)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM