且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用travis-ci的.travis.yml来为Node.js应用程序提供环境参数?

更新时间:2023-11-14 21:23:34

更新:Travis现在支持定义变量通过他们的Web用户界面直接在构建呼叫中心。所以,除非你需要为您的 .travis.yml 文件手动生成本地加密变量(根据下面的原始答案),这似乎是使用Travis CI获取环境变量的最简单方法。 / p>




我不确定关于Node.js的具体细节,但如果要使用 QINIU_ACCESS_KEY QINIU_SECRET_KEY 在您的 .travis.yml 中,而不是纯文本,使他们安全环境变量



步骤0:安装travis宝石(安装Rubygems ,如果你避风港已经不了了,不知道是否有另一种方式 travis 命令或另一种执行下面步骤1的方式):

  $ gem install tr​​avis 

步骤1:加密值,注意结果:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ pre>

步骤2:将值添加到您的 .travis.yml 文件中:

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


(多个密钥叫 secure 没问题)



下一次您的应用程序经过Travis,您应该在Config行中看到:


Env:QINIU_ACCESS_KEY = [安全] QINIU_SECRET_KEY = [安全]


更多*** Q& As可能是帮助(它在Ruby on Rails环境中,但是它们处理这个问题)在这里:




I use travis-ci to test my node.js application. Because the application need users login with Access Key and Secret Key to test, I need to specify these two keys in travis-ci's .travis.yml file. So How can i do this? And how to get these environment parameters in Node?

Like these two parameters: 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 like this:

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 this test file? https://github.com/ikbear/nodejs-sdk/blob/feature/copy_and_move_file/test/rs.test.js

Update: Travis now supports defining variables directly in build respositories via their web user interface. So, unless you have a need to generate local encrypted variables manually for your .travis.yml file (as per original answer below), this seems like the easiest way to get an environment variable working with Travis CI.


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

Step 0: Install the travis gem (Install Rubygems if you haven't got it already; not sure if there's 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 the values to your .travis.yml file:

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

(Multiple keys called secure are no problem)

Next time your app goes through Travis, you should see on the Config line:

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

More *** Q&As that may be of assistance (it's in a Ruby on Rails context, but they deal with this issue) are here: