简体   繁体   中英

Accessing Travis Secure Environment Variables Node.js/PostgreSQL

I have a database uri that I wanted to secure in my travis yml file. I followed the travis docs to encrypt the following environment variable: PROD_DB_URI = MY_DB_URI

I then replaced the URI in my actual database file with this new environment variable that I expect to have access to.

Here is where I added it:

const Sequelize = require('sequelize');
let privateKey;
if (process.env.PROD_DB_URI) {
 privateKey = process.env.PROD_DB_URI;
} else {
 privateKey = require('./../../testingKeys.js').dbKey;
}
const DB = new Sequelize(privateKey);

My travis yml file looks like this:

language: node_js
 node_js:
 - '4'
 env:
   global:
   - CXX=g++-4.8
   - secure: s6/R8v6Nxe8Vw0gnge+0/...
 addons:
   apt:
     sources:
     - ubuntu-toolchain-r-test
     packages:
     - g++-4.8
 after_success: npm run coverage

I tried running travis and it is unable to see the encrypted PROD_DB_URI variable and says its undefined. I even looked at the travis logs and when it exports environment variables it doesn't show the decrypted variable. The logs show:

Setting environment variables from .travis.yml

$ export CXX=g++-4.8

No other variables are being exported. I have also checked to see if the process.env.TRAVIS_SECURE_ENV_VARS was returning true, and it was.

I also saw in the travis docs that you can also add environment variables in their dashboard. I added the key, value pair in the dashboard as PROD_DB_URI = MY_DB_URI. Travis again says its undefined.

Is there something that I am missing? Am I not accessing the secure environment variables properly?

For more refer this link .


In your .travis.yml file add:

env:
- PROD_DB_URI=$PROD_DB_URI

PROD_DB_URI should be set as environment variable in travis

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM