Accessing username / committer's email from Codebuild build pipeline

Viewed 352

As part of my AWS Codebuild pipeline, I am sending a Slack notification that includes the commit ID, which I obtain from the environment variable CODEBUILD_RESOLVED_SOURCE_VERSION as documented here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

This is good, but I also want to access the name or email of the person who made the commit.

How can I possibly obtain that in the same way as I obtain the CODEBUILD_RESOLVED_SOURCE_VERSION?

1 Answers

CodeBuild webhook-triggered builds include the .git metadata. You should be able to retrieve this using the Git CLI, e.g.,:

git log -1 --format="%an <%ae>"

Which gives something like:

John Doe <jdoe@example.com>

The aws/codebuild/standard Docker image comes with Git pre-installed.

Related