Set build meta-data from node script

Hi there, I have the following job yml

  - command:
      - "yarn setup"
      - "cd react-native"
      - "yarn bitrise-aso-upload-screenshots ${APP_PLATFORM} ${APP_TYPE}"
      - "FASTLANE_DIR=$(buildkite-agent meta-data get FASTLANE_DIR)"
      - "echo FASTLANE_DIR: ${FASTLANE_DIR}"
      - "cd ${FASTLANE_DIR}"
      - "FASTLANE_COMMAND=$(buildkite-agent meta-data get FASTLANE_COMMAND)"
      queue: "v1"
      - docker#v3.5.0:
          mount-ssh-agent: true
          image: "languagedrops/buildkite-aso:0.3"
          privileged: true
          userns: "host"
            - "BUILDKITE"
            - "BUILDKITE_JOB_ID"
            - "APP_PLATFORM"
            - "APP_TYPE"

and inside yarn bitrise-aso-upload-screenshots ${APP_PLATFORM} ${APP_TYPE} script (which is node js script) I’m trying to set the meta-data values with:

childProcess.execSync(`buildkite-agent meta-data set FASTLANE_DIR "${some value}" --job ${process.env.BUILDKITE_JOB_ID}`)

Unfortunately, it doesn’t work FASTLANE_DIR and FASTLANE_COMMAND are not set.

Could you please advise how to make it work, did I miss something in how I set or get meta-data?

Hey @Anton welcome to the community!

I think you are setting everything appropriately, so you should be able to see that build meta-data. The first thing I’d ask you to do is verify that your build meta-data is being set as expected (Using Build Meta-data | Buildkite Documentation), and then we can take it from there.

Hi @Anton,

As @jeremy mentioned, your meta-data command looks good. But I’m a bit worried it could be returning an error if it is missing some environment variables like API token or something and that could be missed by your script if it’s not checking the result.

Can you confirm whether childProcess.execSync passes the parent process environment variables along to the child and whether you are checking the output and return code of the command it’s running to ensure it is executing properly?
Part of me thinks it probably isn’t, otherwise, you wouldn’t have to explicitly pass the --job flag either as it will be pulled from the environment.