How to detect a travis rebuild?

Travis has a “Restart build” button that allows you to restart a specific build. I want my CI to skip some build steps on rebuilds. I was wondering if there is any way to detect that the build is triggered from a “Restart build” as opposed to triggered from github push/merge?

I took a look at the travis default environment variables but didn’t find anything helpful.

This seems contrary to the whole purpose of a rebuild. You restart a build when something went wrong. So you want nothing from the previous build to remain.

If you say what you want to achieve, we’ll probably be able to suggest a cleaner way.

For now, I can say that a build cache is still saved on a job failure if the build manages to get to that stage – so you can use that to pass information.

Rather than rebuilding the failed build, perhaps you can select “More options” -> “Trigger build” and kick off a fresh build on a branch, and add an environment variable in the custom config.