If you have an open source Golang project on Github and the project is forked, the Travis CI build will no longer work for the forked project. The reason is that Travis fetches the Golang project and puts it inside the Gopath according to your repository path. In my case, I forked the project github.com/elastic/packetbeat to github.com/ruflin/packetbeat. On my local setup I still put it under the path $GOPATH/src/github.com/elastic/packetbeat as this is where the package is expected by Golang. But as Travis pulls the project from my repository, it puts it into $GOPATH/src/github.com/ruflin/packetbeat. To solve this issue, the following code must be added to your .travis.yml file:

  - mkdir -p $HOME/gopath/src/github.com/elastic/packetbeat
  - rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/elastic/packetbeat/
  - export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/elastic/packetbeat
  - cd $HOME/gopath/src/github.com/elastic/packetbeat

These are the exact same commands Travis uses to set up the project, but with the changed path. This means Travis sets up the project twice, but since all of these commands are very fast, this is not an issue.

It is likely that there is an even simpler way to do this, such as overwriting where Travis should pull the directory, but so far I haven’t found such a solution. If you use a different solution, please mention it in the comments so that I can update the post.