【问题标题】:Write GitLab CI variables to file将 GitLab CI 变量写入文件
【发布时间】:2020-11-04 07:32:04
【问题描述】:

我怎样才能像这样将 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"}

我该如何解决这个问题?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-10-21
      • 2020-03-11
      • 2017-09-05
      • 1970-01-01
      • 2021-07-04
      • 2018-07-25
      • 2018-01-11
      • 1970-01-01
      • 2020-08-20
      相关资源
      最近更新 更多