Debug your R package on Travis CI via SSH

If you can’t replicate the error locally, you can SSH into a Travis server to interactively debug your R package.

John Blischak

Table of Contents

Ideally if R CMD check passes on your local machine, then hopefully it will also pass when run on remote CI servers. But of course this isn’t always the case, and it’s a great way to find bugs (since your users won’t have the exact same setup as your local machine). Often the error messages are sufficient for you to be able to guess at the solution. But if you’ve pushed multiple commits to try and fix the problem, and the CI jobs are still failing, it is probably worth investing the time to interactively debug the job on the remote server. In this post, I’ll describe how to do this for Travis CI. Travis CI documents the process in Running Build in Debug Mode, and below I tailor this specifically for debugging R packages. vs

Before going any further, you should go check the URL of your Travis CI jobs, because this will affect the steps below. Initially Travis CI hosted open source repositories on and private repositories on However, now they are migrating all projects to use Thus if you setup Travis prior to May 2018, you are likely using; whereas if you set it up post May 2018, you are likely using See the documentation Open Source on for all the details. Currently the migration of open source projects from to is in Beta, so I wouldn’t recommend trying to migrate your repository unless you were really motivated to use the new GitHub App version of Travis CI.

Email for debug access

To start, you’ll need to email Travis CI support at to activate debug mode for your repository. They got back to me in about two hours.

The reason that this feature is not automatically enabled is for security reasons. Below is the explanation from the email they sent me that confirmed activation of debug mode:

The reason this is not enabled by default for public repositories is that anyone who happens to stumble across a log containing the SSH access can make a connection to the VM and potentially read out the secret environment variables.

You can learn more in the section Security considerations. Briefly, while only you are able to initiate a debugging session, if someone with malicious intent were to be watching that exact build log, they could also run the SSH command to login. This is mainly a concern if you’ve added encrypted environment variables ( e.g. SSH deploy keys or personal access tokens). A standard setup to test an R package, e.g. with usethis::use_travis(), does not involve any sensitive information, so this likely isn’t a concern for you.

Get your API token

Once you’ve received your email confirmation from Travis CI support, you can obtain your authentication token. The token allows only you to trigger a debug build for your repository. Thus do not save this anywhere that others can view. If you’re using, go to If you’re using, go to (screenshot below).

Travis API token from
Travis API token from

Find job ID number

Next you need to find the job ID number of the job you want to restart in debug mode. The key is to not use the build ID number. When you first go to the build log, the URL will be https://travis-ci.<org|com>/<username>/<repository>/builds/<build ID>. When you click on the individual job that you want to debug, the URL will change to https://travis-ci.<org|com>/<username>/<repository>/jobs/<job ID>. Copy-paste the job ID. This isn’t sensitive information (because it’s already public), so you don’t need to be careful about it. If you only have one job, then click on either “Job log” or “View config” to change the URL.

Restart job in debug mode

With both the authorization token and job ID, you can trigger the Travis API to restart the job in debug mode. Specifically you will use the debug endpoint of the Travis API v3.1

Open a terminal and copy-paste the following API call, replacing the placeholders with your actual API token and job ID. Also make sure to change the URL to if that is what you are using.

$ curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Travis-API-Version: 3" \
  -H "Authorization: token <API token>" \
  -d "{\"quiet\": true}" \<job ID>/debug

If this is successful, it will return a JSON blob that looks like the following:

  "@type": "pending",
  "job": {
    "@type": "job",
    "@href": "/job/<job ID>",
    "@representation": "minimal",
    "id": <job ID>
  "state_change": "created",
  "resource_type": "job"

Now go to the page of the job you just restarted. Recall that the URL will look like https://travis-ci.<org|com>/<username>/<repository>/jobs/<job ID>. Once the job starts, a few steps will be done prior to providing you SSH access:

Note that the last item could be a potential problem. If you suspect your errors may be due to an outdated dependency, you will want to first clear the package cache by clicking on “More options” -> “Caches” and deleting the relevant cache.

After these steps, the following message will be printed in the build log:

Debug build initiated by <username>
rm: cannot remove ‘/home/travis/.netrc’: No such file or directory
Setting up debug tools.
Preparing debug sessions.
Use the following SSH command to access the interactive debugging environment:
ssh <random string>
This build is running in quiet mode. No session output will be displayed.

Copy-paste the ssh command into your terminal. Note that you’ll likely receive a warning about the authenticity of the host, which you can accept:

$ ssh
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is SHA256:8GmKHYHEJ6n0TEdciHeEGkKOigQfCFuBULdt6vZIhDc.
Are you sure you want to continue connecting (yes/no)? yes

This will drop you into a tmate2 session. Note that the tmate terminal behaves a little differently than a typical terminal. You can move up and down the command history with the up and down arrows, but if you want to do anything more complicated, e.g. reverse search, you’ll need to first invest some time in learning the tmux key bindings.

Now you can start interactively debugging your package! The next steps will be specific to your package and the given error. If one of your dependencies is failing to install, you can open R and try to install a previous version. Or you could try installing some system libraries with APT. If the error is in the check step, you can run the installation step with the convenience function travis_run_install. There are convenience functions for each of the potential steps in .travis.yml, and you can see the default steps in the R-specific build documentation.

If you know that R CMD check results in a warning or an error, do not run travis_run_script. The SSH session will automatically terminate if there is an error. Instead you can run devtools::install() to install your R package and then interactively test it. If you’re using testthat, you can run devtools::test(filter = "<string>") to run the specific tests that are failing.

To give you a sense of how much control you have, the last time I had to interactively debug my R package, I suspected that pandoc 2 was causing the issue. Thus after running devtools::test() to confirm the error, I installed pandoc and then reran devtools::test() to confirm the error was fixed.

sudo apt remove pandoc
sudo dpkg -i pandoc- 


A few final notes that may be helpful as you debug your Travis build:


With any luck you won’t have to interactively debug your R package directly on a Travis server. But if you can’t replicate the error locally, using debug mode is much easier than debugging by the method of guess-push-hope-repeat.

Do you have any tips for debugging an R package on Travis? Any harrowing debugging adventures to share?

  1. Note that this viewing the API documentation requires you to login.

  2. A fork of tmux

  3. This was the latest of the 1.x series that had a deb file available.


If you see mistakes or want to suggest changes, please create an issue on the source repository.


Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".


For attribution, please cite this work as

Blischak (2019, March 26). John Blischak's blog: Debug your R package on Travis CI via SSH. Retrieved from

BibTeX citation

  author = {Blischak, John},
  title = {John Blischak's blog: Debug your R package on Travis CI via SSH},
  url = {},
  year = {2019}