How to use travis-ci's .travis.yml to provide environment parameters for Node.js Application?

前端 未结 2 1328
名媛妹妹
名媛妹妹 2021-02-09 20:30

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

相关标签:
2条回答
  • 2021-02-09 21:08

    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 StackOverflow Q&As that may be of assistance (it's in a Ruby on Rails context, but they deal with this issue) are here:

    • How to deploy an rails app on heroku from travis-ci?
    • Using secret api keys on travis-ci
    0 讨论(0)
  • 2021-02-09 21:18

    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 讨论(0)
提交回复
热议问题