Build # in app version

Motivation: incontinues deployment there is some sense indicating build number in the app version. not just GIT hash (nobody knows the meaning of …)

In this example: we will use sbt + docker plugin. after understanding the idea you can achieve this in many different methods.

Basicallywe need to pass build# into our app, the build# is provided by the build system, Jenkins sets a ENV variable named $BUILD_NUMBER in the scope of the running build. we will use it and pass to a docker container. later when needed (from some api call) we will fetch the ENV var that was passed to the container by sbt from the Jenkins machine.

Finished ! only thing left is to call the ENV variable when needed, for example in a controller for an api call :

Any Controller

Scala

1

2

3

4

5

6

7

8

objectSomeControllerextendsController{

valversion=sys.env.getOrElse("APP_VERSION","n/a")

valbuildNumber=sys.env.getOrElse("BUILD_NUMBER","n/a")

defgetVersion=Action.async{

Future.successful(Ok(s"$version-$buildNumber"))

}

}

Bonus ! in the UI you can add a direct link from the App version to Jenkins simply by checking on the URL structure on your build and add the build number in it! this way is some 1 want to check if his changes are already committed to this build he can click on the product version in the UI and view the change list on Jenkins!