Getting old commit hash [solved]

Hey, loving drone, so first off thanks for all the work on it!

Quick question, how would I run git rev-parse HEAD~10 in one of my steps? I tag my docker image builds with the commit hash and push to a private repository, I want to delete the image once there are 10 new commits since then, so I’m not paying for storage I don’t need.

Ideally if I could put this into an env variable and then reference it in my deploy section that’d be awesome. Thanks

I’m having trouble correlating the title with the details in this thread, so maybe this can be clarified a bit? Phrasing questions in the format of steps to reproduce / expected result / actual result are preferred since it makes it easier for us to troubleshoot and offer assistance.

Getting old commit hash

Is this related to pull requests? If yes, I recommend the below threads which provide some background and workarounds.

[1] Pipeline Event Merge Requests w/GitLab
[2] http://discuss.harness.io/t/solved-clone-from-git-not-reflecting-change-in-commit/818
[3] Edit a ZeroNorth Ruleset

So Drone sets the current commit hash with DRONE_COMMIT.

I want to get the commit hash from X commits ago, ex: the hash from 5 commits ago, so that I can clean up my private docker registry, and not keep adding new tags and layers forever.

Using drone’s docker and gcr plugins will continue to add new layers forever without ever cleaning up.

Turns out you can do this in the official gcloud docker image, so if anyone else wants to cleanup old images, you can run something like this too, inside the commands list of the google/cloud-sdk:latest image

gcloud container images delete -q gcr.io/project/app:$(git rev-parse HEAD~5)

I didn’t know running git commands would work in the official gcloud docker image in my pipeline but this works just fine, leaving this here in case someone else wants to do this! Thanks for the quick reply.