Look here for a recipe: https://twindb.com/building-rpm-on-travis-ci-in-docker-containers/
Also, this page shows how to use bild stages to avoid many long builds that will fail: https://docs.travis-ci.com/user/build-stages