Search code examples
androidgithubtravis-ciandroid-build

What is the best way to build code which is stored in public repo and need token key with CI?


I have an Android project that need token key which I store in a public repo. I do not commit my key to the repo. I integrate my repo with Travis CI for automated build. But, the building process will be failed because no token key is found. How should I provide the key to the CI without committing it to the repo?


Solution

  • Travis allows you to store encrypted environment variables for precisely this scenario. See here:

    Encrypting environment variables

    Encrypt environment variables with the public key attached to your repository using the travis gem:

    1. If you do not have the travis gem installed, run gem install travis.

    2. In your repository directory, run:

       travis encrypt MY_SECRET_ENV=super_secret --add env.matrix
      
    3. Commit the changes to your .travis.yml.

    Encryption and decryption keys are tied to the repository. If you fork a project and add it to Travis CI, it will not access to the encrypted variables.

    The encryption scheme is explained in more detail in Encryption keys.