Search code examples
jenkinsplayframeworksbtsbt-native-packager

Use Jenkins build number within build.sbt in play to build RPM with sbt-native-packager


This question is somehow related to Using Jenkins BUILD NUMBER in RPM spec file.

You can access the build number in a Jenkins process using the environment variable ${BUILD_NUMBER}. But how can I use this environment variable within my Play! build.sbt file to set rpmRelease := "..." to the actual build number?

The RPM is built within Jenkins using the simple Shell command activator rpm:packageBin.


Solution

  • You can place scala code in your build.sbt file, so something like this should work:

    rpmRelease := sys.env("BUILD_NUMBER")
    

    or if you need to provide a default value:

    rpmRelease := sys.env.get("BUILD_NUMBER").getOrElse("SOME DEFAULT VALUE")