Today, the BUILDKITE_TRIGGERED_FROM_* variables are set to "" when you click “Rebuild” button on a build that was triggered from another build. This seems unintuitive to me since Rebuilding should preserve all of the environment variables the original one kicked off with. The exception could be BUILDKITE_SOURCE.
Ooh, good spot @ngan! Technically a rebuilt build wasn’t triggered, so doesn’t have a triggered from build, sorry. You could instead look at the BUILDKITE_REBUILT_FROM_* variables?
Yeah, I think that’s the only way to do it for now. You might need to use the REST API to walk the builds. But I do agree that the rebuilds should include those trigger build details. I’ll see if we can add that env, but I can’t promise when it will happen sorry.