php - 将 GitLab CI 变量写入文件
问题描述
我怎么能像这样将 GitLab CI 变量写入配置文件:
test:
stage: test
script:
- touch "config.json"
- echo "{"database":"$DB_NAME"}" >> config.json
变量无法解析。我总是在文件中得到以下 json config.json
:{"database":"$DB_NAME"}
但我想要这个{"database":"my_database_name"}
我该如何解决这个问题?
解决方案
我通过带有如下参数的shell脚本解决了我的问题:
test:
stage: test
script:
- bash setup_config_for_tests.sh $DB_NAME $DB_PASSWORD $SALT $HOST_PROD $USERNAME_PROD $PASSWORD_PROD
#!/bin/bash
# create config file
touch "config.json"
# write config json to config file
echo "{\"param1\": \"${1}\"}" >> config.json