Travis CI - 在 .travis.yml 中使用存储库环境变量

Travis CI - Using repository environment variables in .travis.yml

我希望在我的 Travis CI 存储库设置中声明环境变量,并在我的 .travis.yml 文件中使用它们来部署应用程序和 post Slack 中的构建通知.

我在我的 Travis CI 存储库设置中设置了环境变量,如下所示:

我的 .travis.yml 文件显示如下:

language: node_js
node_js:
  - '0.12'
cache:
  directories:
    - node_modules
deploy:
  edge: true
  provider: cloudfoundry
  api: $CF_API
  username: $CF_USERNAME
  password: $CF_PASSWORD
  organization: $CF_ORGANIZATION
  space: $CF_SPACE
notifications:
  slack: $NOTIFICATIONS_SLACK

当我将这些值按原样添加到 .travis.yml 文件时,一切都按计划进行。

但是,当我尝试引用存储库中设置的环境变量时,我没有收到有关构建状态的 Slack 通知,并且部署失败。

我是否正确地遵循了这个过程,或者我在监督什么?

我认为在 Travis CI 的序列中读取您的环境变量可能为时过早。

我的建议是使用 travis command-line tool.

加密它们

例如

$ travis encrypt
Reading from stdin, press Ctrl+D when done
username
Please add the following to your .travis.yml file:

secure: "TD955qR6qvpVIz3fLkGeeUhV76deeVRaLVYjW9YjV6Ob7wd+vPtACZ..."

Pro Tip: You can add it automatically by running with --add.

然后我会 copy/paste secure: "TD955qR6qvpVIz3fLkGeeUhV76d..." 结果在你的 .travis.yml 文件中的适当位置:

language: node_js
node_js:
  - '0.12'
cache:
  directories:
    - node_modules
deploy:
  edge: true
  provider: cloudfoundry
  api:
    secure: "bHU4+ZDFeZcHpuE/WRpgMBcxr8l..."
  username:
    secure: "TD955qR6qvpVIz3fLkGeeUhV76d..."

您可以获得有关如何在 Travis 上加密敏感数据的更多详细信息CI here

希望对您有所帮助。