GitHub Deployments - Set environment variables

Hello,

I’m working on simplifying the way our GitHub deployments work with Buildkite. Currently, we’re extracting and setting additional environment variables for our deployments by reading the JSON-encoded deployment payload we send across as part of the GitHub deployment trigger.

Is it possible to simplify this and get the environment variables set directly for us in some way? For example, I know the Buildkite build message for the deployment is taken from the description field of the deployment payload. Wondering if there’s something similar we can do there.

Thank you, and apologies if this has been asked before!

Hi @craig.thompson.hive

Welcome back to the Buildkite Community Forums!

The environment variables can be set using environment hooks which is a shell script that is sourced at the beginning of a job and it is stored in the agents hook directory. More details on how to configure this can be found here
After its configuration, your deployments running on the agent the environment hook was configured will pick the environment variables that was set. Please let me know if this helps

Thanks @Michael, I thought that might be the case. That’s actually what we’re doing at the moment via a custom script:

if [[ "${BUILDKITE_GITHUB_DEPLOYMENT_PAYLOAD:-{}}" != "{}" ]]; then
	echo -e "~~~ :github: Retrieving PR environment variables from deployment payload..."
    export BUILDKITE_PULL_REQUEST_BASE_COMMIT=$(echo "${BUILDKITE_GITHUB_DEPLOYMENT_PAYLOAD:-null}" | jq -r '.pull_request.base.sha // ""')
fi

Was hoping there might be some native solution within Buildkite to achieve this, but it’s working okay so we’ll leave it there!

Thanks again