将GitLab CI变量写入文件

时间:2020-07-14 21:10:21

标签: php continuous-integration gitlab yaml gitlab-ci

我如何像这样将GitLab CI变量写入配置文件:

test:
  stage: test
  script:
    - touch "config.json"
    - echo "{"database":"$DB_NAME"}" >> config.json

无法解析变量。我总是在文件config.json中得到以下json:{"database":"$DB_NAME"},但我想要这个{"database":"my_database_name"}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我通过带有以下参数的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