Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

travis-ci

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:

Travis CI repository environment variables

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?

like image 493
Simon Finney Avatar asked Nov 16 '15 12:11

Simon Finney


People also ask

Which of the following file is used to configure the Travis CI?

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.

Which of the following encryption scheme is used by Travis CI?

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.


1 Answers

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.

like image 197
Dominic Jodoin Avatar answered Oct 11 '22 14:10

Dominic Jodoin