I'm using Travis for continuous build and integration.
after_success:
- sbt publish
While we want Travis to build all of our branches and pull requests, we only want it to publish when on master branch.
publishTo <<= version { (v: String) =>
val nexus = s"asdf"
/* Don't let Travis publish when building pull requests.
* $TRAVIS_PULL_REQUEST == "false" if it's not a pull request. So we wan't publishTo to be
* None when TRAVIS_PULL_REQUEST != false.
*/
if(Try(sys.env("TRAVIS_PULL_REQUEST")).getOrElse("false") != "false")
None
/* Don't let Travis publish except when building master. */
if(Try(sys.env("TRAVIS_BRANCH")).map(_ != "master").getOrElse(false))
None
else if(v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "snapshots")
// don't let Travis publish releases, either
else if(Try(sys.env("TRAVIS")).getOrElse("false") == "true")
None
else
Some("releases" at nexus + "releases")
})
The problem with this approach is that Travis compiles branches twice because it fails publishing at the very last step.
How can Travis be completely prevented from running sbt publish when on non-master branch?