How to use travis-ci.travis.yml to provide environment settings for a Node.js application?

I use travis-ci to test my node.js. application Since the application requires a login with an access key and a secret key for verification, I need to specify these two keys in the travis-ci.travis.yml file. So how can I do this? And how to get these environment parameters in Node?

Like these two options: https://github.com/ikbear/nodejs-sdk/blob/feature/copy_and_move_file/test/rs.test.js#L22

I want to specify them in .travis.yml as follows:

language: node_js node_js: - 0.8 - 0.6 - 0.4 env: - QINIU_ACCESS_KEY = '2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov' QINIU_SECRET_KEY = 'CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK' 

So how can I get QINIU_ACCESS_KEY and QINIU_SECRET_KEY from my test file? https://github.com/ikbear/nodejs-sdk/blob/feature/copy_and_move_file/test/rs.test.js

+6
source share
2 answers

Update : Travis now supports defining variables directly in storage assemblies through its web user interface. So, if you don’t need to generate local encrypted variables manually for your .travis.yml file (according to the original answer below), this seems like the easiest way to get the environment variable working with Travis CI.


I'm not sure about the specifics of Node.js, but if you want to use QINIU_ACCESS_KEY and QINIU_SECRET_KEY in .travis.yml , not being plain text, make them protected environment variables :

Step 0: install the travis gem ( install Rubygems , if you do not already have it, I'm not sure if there is another way to get the travis command or another way to perform step 1 below):

 $ gem install travis 

Step 1: Encrypt the values, taking note of the result:

 $ travis encrypt QINIU_ACCESS_KEY=2FRuiVGEsA511NS9pNd2uvuSB3k5ozXE_DHCH8Ov $ travis encrypt QINIU_SECRET_KEY=CIRtcmymB3VeIfXebFvYxmMmH9u2oLKW6rffVvoK 

Step 2. Add values ​​to the .travis.yml file:

 env: global: - secure: {{ENCRYPTED_QINIU_ACCESS_KEY}} - secure: {{ENCRYPTED_QINIU_SECRET_KEY}} 

(A few keys called secure not a problem)

The next time your application goes through Travis, you should see the Config line:

Env: QINIU_ACCESS_KEY = [secure] QINIU_SECRET_KEY = [secure]

More StackOverflow Q & as it may be useful (this is in the context of Ruby on Rails, but they deal with this problem):

+13
source

Read here (Using environment variables with Travis-CI!) β†’ https://github.com/dwyl/learn-environment-variables#using-environment-variables-with-travis-ci-

Also, to learn more about Travis, read here (Learn Travis) β†’ https://github.com/dwyl/learn-travis

0
source

All Articles