buildkite / feedback

Got feedback? Please let us know!
https://buildkite.com
25 stars 24 forks source link

passing environment to triggered jobs #253

Closed tnh closed 6 years ago

tnh commented 7 years ago

Currently, we have a pipeline like:

env:
  AWS_DEFAULT_REGION: ap-southeast-2
  ENVIRONMENT: drprod
  ACCOUNT: prod

steps:
- trigger: something-infrastructure
  label: ':tractor: something'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env:
      ENVIRONMENT: drprod
      ACCOUNT: prod

- wait

- trigger: another-thing-infrastructure
  label: ':minibus: Deploy another thing ervices'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env:
      ENVIRONMENT: drprod
      ACCOUNT: prod

what I dont like is

I tried to do something like this but it doesnt work:

- trigger: another-thing-infrastructure
  label: ':minibus: Deploy another thing ervices'
...
    env:
      ENVIRONMENT: ${ENVIRONMENT}

I'm wondering if it would be possible to either

sj26 commented 6 years ago

Hmm, it's YAML, so you could use anchors and references:

env:
  AWS_DEFAULT_REGION: ap-southeast-2
  ENVIRONMENT: drprod
  ACCOUNT: prod

steps:
- trigger: something-infrastructure
  label: ':tractor: something'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env: &TRIGGER_ENV
      ENVIRONMENT: drprod
      ACCOUNT: prod

- wait

- trigger: another-thing-infrastructure
  label: ':minibus: Deploy another thing ervices'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env: *TRIGGER_ENV

Finding a YAML reference is hard, but anchors and references are covered in this tutorial:

https://rhnh.net/2011/01/31/yaml-tutorial/

And there is environment variable interpolation in buildkite-agent v3 so you don't have to repeat the values, either:

env:
  AWS_DEFAULT_REGION: ap-southeast-2
  ENVIRONMENT: drprod
  ACCOUNT: prod

steps:
- trigger: something-infrastructure
  label: ':tractor: something'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env: &TRIGGER_ENV
      ENVIRONMENT: "$ENVIRONMENT"
      ACCOUNT: "$ACCOUNT"

- wait

- trigger: another-thing-infrastructure
  label: ':minibus: Deploy another thing ervices'
  build:
    message: ${BUILDKITE_MESSAGE}
    commit: HEAD
    branch: master
    env: *TRIGGER_ENV
lox commented 6 years ago

I'm going to close this one out, let us know if the yaml references don't solve your problem.