如何在Circleci config.yml中的作业中使用env vars生成文件

时间:2019-06-20 16:19:52

标签: bash shell circleci circleci-2.0

我正在尝试使用我的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

1 个答案:

答案 0 :(得分:0)

我忘了在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

注意:同样,我也忘记在变量周围添加“”。