Use previous step info for trigger step build info

Hi everyone!!

I am trying to use the information of one step to configure a trigger step, in specific, on the step I will get a commit hash and then I want to use it to trigger another pipeline over that specific commit.

Is there a chance to do that? I know I can use that information on the next step by using meta-data but I don’t know how to read it on this case that I don’t want to use it inside the commands but in the step config.

# steps:

steps:
  - label: "Set hash"
    commands:
      - export commit-hash = "346104832969fe31b25760172aba0a84e9c22457" // This is here hardcoded but I get this dynamically from an API and some calculations.
  - wait
  - trigger: my-other-pipeline
     build:
       branch: "${BUILDKITE_BRANCH}"
       message: "${BUILDKITE_MESSAGE}"
       commit: "" // I want to use here the commit-hash

I haven’t been able to see the way to achieve that.

Hey @FNK welcome and good question :+1:

This is definitely possible. There is the BUILDKITE_COMMIT environment variable that houses the commit hash, just like the other env vars you’ve used there. That should give you want you want - to trigger the other pipeline against the specific commit

Hi @paula, thank you for the answer.

The thing is that I am running my pipeline against HEAD and I want to trigger the other pipeline over a different commit that I get on the first step.

AFAIK BUILDKITE_COMMIT cannot be modified.

Hi @FNK,

As shown in below example, you can also set the commit that you want the other pipeline to run when you trigger it

- trigger: "app-sub-pipeline"
  label: "Sub-pipeline"
  build:
    message: "${BUILDKITE_MESSAGE}"
    commit: "<SET_VALUE_OF_COMMIT>"
    branch: "${BUILDKITE_BRANCH}"