Can our Builder build see our Git revision hash?


#1

We’d love to be able to send notifications to various monitoring services that would record the Git revision that’s been deployed or packaged. Is there a way to see the Git revision from inside the build Studio or from inside Builder when a GitHub webhook has triggered a build?


#2

As far as I can tell, no, this functionality doesn’t currently exist. We’re always open to new feature requests, though.


#3

I haven’t fully explored this, but I think you should be able to add core/git as a build dependency and then stash the output of

git rev-parse HEAD

somewhere in the build output to be accessed later. Would that work for your purposes, @smartb-pair?


#4

This comes up all the time and would be really useful. I’ve created an issue for it here:


#5

Yes, that does work and we can probably use this for a few things. Thanks!


#6

In case someone comes along here searching for a solution - especially on how to “stash” the output. I was able to use the do_build() method to supply the git revision:

do_build() {
  set_runtime_env GIT_REVISION $(git rev-parse HEAD 2>&1)
}

The 2>&1 redirect should not be totally necessary though.
And in the corresponding hook I am including it like any other environment variable in a curl command to notify about the deployment:

curl https://monitoring.domain -F revision=$GIT_REVISION

If anyone comes across a better solution, please do let us know.