Travis Authentication with Heroku

Spandana Nallapati
4 min readFeb 19, 2021

A note about Heroku and Travis CI

Heroku is a great platform to use when you are a beginner to building, scaling and deploying your application. It pairs very well with Travis CI, which is a continuous integration service, for monitoring your GitHub projects and running tests.

Setting up Authentication

Once you set up your Travis account, link it your repo and have made a commit to master/main so Travis can build your app and run its tests, it is finally time to deploy your site. If your experience was similar to mine, this next encryption step was a confusing one. Maybe it was my limited knowledge or maybe it was because of recent changes and updates, but I spent quite a few hours trying to find the best solution and below is the fruit of that search pieced together in one place. So, this walk-through is for those of you who’ve gotten stuck and need another source of information about it. This assumes that you’ve gotten to the steps we’ve spoken about above. Let’s jump in -

  1. Install Ruby for your operating system. You can follow the instructions here for your operating system. For Windows it may look like this:
Installation

2. Then use gem (package installer for Ruby) to install the Travis CI command line: $ sudo gem install travis (You may not need the ‘sudo’ depending on your operating system)

Install Travis

3. Travis will need to log in to your GitHub account to continue. If you aren’t able to get it working through the command-line options to enter a password, you may need to create an access token through the GitHub API and make it available to my system. To create an access token, go here

4. Give the token a note and ensure the above three boxes are clicked on the GitHub personal access token page.

Select Repo, user:email and read:org

5. After you press Generate token a long string will be generated which you can use in the next step.

Your GitHub Token

6. Once you have the token, open up your _netrc file (it may be called .netrc depending on your system) in your home directory. You can usually find this on your C: drive under your username.

7. There may already be other entries in this file and if so, add the following at the bottom:

machine github.com

  • login <your GitHub login username, not email>
  • password <the key generated by GitHub>

machine api.github.com

  • login <your GitHub login username, not email>
  • password <the key generated by GitHub>
This file may or may not empty

8. Save this file.

9. Using the terminal, cd into your repo folder and run the following command to have the Travis CI command line tool update your travis.yml (*below the “—” denotes a double dash*):

  • travis login — pro

10. If this doesn’t log you in automatically, then use the following command:

  • travis login — pro — github-token [paste your token here]

10a. Then, when you see that you’ve been successfully logged in, type the following command:

  • travis encrypt $(heroku auth:token) — add deploy.api_key — pro

11. You can check your travis.yml to see if it changed as a result of this command. Once done, pushing to git should not have Travis kick off correctly and deploy to Heroku successfully.

Congratulations! Your site should be deployed and pipelined!

--

--

Spandana Nallapati
0 Followers

My name is Spandana Nallapati and I am a fullstack software engineer, who, previously, worked as a developmental behavioral pediatrician.