如何在 bitbucket 管道上填充参数文件

How to populate a parameter file on bitbucket pipelines

我必须在我的管道中使用变量填充 parameters.yml 文件。文件中大约需要 60 行。所以我尝试使用大约 60 个 echo 语句来填充文件,并使其易于配置,但是当使用验证器时,它说我的管道文件无效,因为我需要使用字符串或管道。

是否有其他选项可以让我将多行字符串回显到文件中,或者是否有其他选项可以使用环境变量填充该文件?

这是我现在尝试的方式:

pipelines:
  default:
    - step:
        name: install and test
        caches:
          - composer
          - node
          - vendor
        script:
          - npm install
          - npm install -g gulp
          - echo "parameters:" > app/config/parameters.yml
          - echo "    database_driver: pdo_mysql" >> app/config/parameters.yml
          - echo "    database_host: $DB_HOST" >> app/config/parameters.yml
          - echo "    database_port: $DB_PORT" >> app/config/parameters.yml
          - echo "    database_name: $DB_NAME" >> app/config/parameters.yml
          - echo "    database_user: $DB_USER" >> app/config/parameters.yml
          - echo "    database_password: $DB_PASS" >> app/config/parameters.yml
          - echo "    redis.dsn.cache: \"$REDIS\"/0" >> app/config/parameters.yml
          - echo "    redis.dsn.doctrine: \"$REDIS/1\"" >> app/config/parameters.yml
          - echo "    redis.dsn.session: \"$REDIS/2\"" >> app/config/parameters.yml
          - echo "    mailer_transport: $MAIL_TRANSPORT" >> app/config/parameters.yml
          - echo "    mailer_host: $MAIL_HOST" >> app/config/parameters.yml
          - echo "    mailer_user: $MAIL_USER" >> app/config/parameters.yml
          - echo "    mailer_password: $MAIL_PASS" >> app/config/parameters.yml
          - echo "    mailer_port: $MAIL_PORT" >> app/config/parameters.yml

我认为验证器对我在配置中回显 yaml 有一些问题。我就是这样修复它的:

pipelines:
  default:
    - step:
        name: install and test
        caches:
          - composer
          - node
          - vendor
        script:
          - npm install
          - npm install -g gulp
          - echo "parameters:" > app/config/parameters.yml
          - echo "    database_driver:\ pdo_mysql" >> app/config/parameters.yml
          - echo "    database_host:\ $DB_HOST" >> app/config/parameters.yml
          - echo "    database_port:\ $DB_PORT" >> app/config/parameters.yml
          - echo "    database_name:\ $DB_NAME" >> app/config/parameters.yml
          - echo "    database_user:\ $DB_USER" >> app/config/parameters.yml
          - echo "    database_password:\ $DB_PASS" >> app/config/parameters.yml
          - echo "    redis.dsn.cache:\ \"$REDIS/0\"" >> app/config/parameters.yml
          - echo "    redis.dsn.doctrine:\ \"$REDIS/1\"" >> app/config/parameters.yml
          - echo "    redis.dsn.session:\ \"$REDIS/2\"" >> app/config/parameters.yml
          - echo "    mailer_transport:\ $MAIL_TRANSPORT" >> app/config/parameters.yml
          - echo "    mailer_host:\ $MAIL_HOST" >> app/config/parameters.yml
          - echo "    mailer_user:\ $MAIL_USER" >> app/config/parameters.yml
          - echo "    mailer_password:\ $MAIL_PASS" >> app/config/parameters.yml
          - echo "    mailer_port:\ $MAIL_PORT" >> app/config/parameters.yml
          - sed -i 's/\ / /g' app/config/parameters.yml

基本上我无法回显有效的 yaml,所以我使用 sed 修改文件来修复它,因此 yaml 变得有效。