【问题标题】:How to generate a file with env vars in a job in Circleci config.yml如何在 Circleci config.yml 的作业中生成带有环境变量的文件
【发布时间】:2019-06-20 16:19:52
【问题描述】:

我正在尝试使用我的 circleci 环境变量在我的 Circleci 配置文件中生成一个 env.ts 文件。我尝试了以下代码:

steps:
  - run:
          name: Setup Environment Variables
          command: 
            echo "export const env = { 
              jwtSecret: ${jwtSecret},
              gqlUrl:  ${gqlUrl}, 
              engineAPIToken:  ${engineAPIToken},
              mongodb:  ${mongodb},
              mandrill:  ${mandrill},
              gcpKeyFilename:  ${gcpKeyFilename},
              demo: ${demo}, 
              nats: ${NATS}, 
              usernats:  ${usernats}, 
              passnats:  ${passnats} };" | base64 --wrap=0 > dist/env.ts

但它会输出这个:

#!/bin/sh -eo pipefail
# Unable to parse YAML
# mapping values are not allowed here
#  in 'string', line 34, column 24:
#                   jwtSecret: ${jwtSecret},
#                            ^
# 
# -------
# Warning: This configuration was auto-generated to show you the message above.
# Don't rerun this job. Rerunning will have no effect.
false
Exited with code 1

【问题讨论】:

    标签: bash shell circleci circleci-2.0


    【解决方案1】:

    command: |之后忘记写管道了

    steps:
      - run:
              name: Setup Environment Variables
              command: |
                echo "export const env = { 
                  jwtSecret: '${jwtSecret}',
                  gqlUrl:  '${gqlUrl}', 
                  engineAPIToken:  '${engineAPIToken}',
                  mongodb:  '${mongodb}',
                  mandrill:  '${mandrill}',
                  gcpKeyFilename:  '${gcpKeyFilename}',
                  demo: ${demo}, // it's a boolean
                  nats: '${NATS}', 
                  usernats:  '${usernats}', 
                  passnats:  '${passnats}'
                };" > dist/env.ts
    

    注意:我也忘记在变量周围添加 ''。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 2013-01-28
      • 2020-10-07
      • 1970-01-01
      相关资源
      最近更新 更多