I’m a fan of Travis CI and use it for continuous integration across pretty much all my open-source projects on GitHub. From time to time, I need to obtain a URL to a file in the repository in my build, e.g. to point a particular tool to it, in a way that respects branches as well as pull requests from forks.

Here’s how I do it:

Explanation:

To see this in action, check out the build file of one of the projects I contribute to. We construct a URL to an OpenAPI specification to validate via Swagger Validator Badge. For more information about default environment variables in Travis, see this page.