SHA1 of previous build

Hi,

I’d like to fetch the commit hash of the previous build. The current one is available as CIRCLE_SHA1, and there is also CIRCLE_COMPARE_URL, but no sha1 of previous build.
Is there an easier way than parsing CIRCLE_COMPARE_URL?

Thanks in advance!

4 Likes

Even better would be to have the SHA1 of the last build and the SHA1 of the last successful build.

2 Likes

Hi there, any update on this? It would be extremely useful.
I’m curious how people are getting around this currently.
Thanks

So to do this within the build, create an API_KEY in your build with full permissions, and run this inside your build

LAST_SUCCESSFUL_COMMIT=$(curl -Ss -u "$API_KEY:" "https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME?filter=completed&limit=1" | jq -r '.[0]["vcs_revision"]')

4 Likes

+1 to this feature request. It would be very nice to have this info readily available to help decrease build times. Tools such as Lerna, Bazel and others can make use of this information to only rebuild what needs building.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.