I'm looking to declare environment variables in my Travis CI repository settings and use them in my .travis.yml file to deploy an application and post a build notification in Slack.
I've set environment variables in my Travis CI repository settings like so:
My .travis.yml file appears as the following:
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
When I add the values into the .travis.yml file as they are, everything works as planned.
However, when I try to refer to the environment variables set in the repository, I receive no Slack notification on a build status, and the deployment fails.
Am I following this process correctly or is there something I'm overseeing?
Configuration. Travis CI is configured by adding a file named . travis. yml , which is a YAML format text file, to the root directory of the repository.
Encryption scheme # Travis CI uses asymmetric cryptography. For each registered repository, Travis CI generates an RSA keypair. Travis CI keeps the private key private, but makes the repository's public key available to those who have access to the repository.
I think it is probably too early in Travis CI's sequence for your environment variables to be read.
What I would suggest is to rather encrypt them using the travis
command-line tool.
E.g.
$ 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.
Then I would copy/paste the secure: "TD955qR6qvpVIz3fLkGeeUhV76d..."
result at the appropriate place in your .travis.yml file:
language: node_js node_js: - '0.12' cache: directories: - node_modules deploy: edge: true provider: cloudfoundry api: secure: "bHU4+ZDFeZcHpuE/WRpgMBcxr8l..." username: secure: "TD955qR6qvpVIz3fLkGeeUhV76d..."
You can have more details about how to encrypt sensitive data on Travis CI here.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With