Passing build variables to commands

I would like to use build.pull_request.labels in a step command but am struggling since it seems like the main purpose of this variable is for conditionals. Is it possible to use this variable or should I resort to GitHub API?

Hey @Benjamin,
you are right build.pull_request.labels is primary designed to use if (conditional) logic, not for direct use in commands. There are some ways to work around, depends on your needs.
Basically, you can set metadata based on the build.pull_request.labels condition, and then reference that metadata in your commands. We have some similar answer on our community forum, please check here.

But if you need the labels directly in your command you can fetch them using the GitHub API.

Thanks,

1 Like

Hey @ivanna thanks for confirming. I noticed that the get build API returns PR labels for jobs triggered by a PR.

I will probably try to grab them from there since GitHub API would be more involved to setup. Since I use quite a few PR labels I am thinking it is more straight forward to pass the labels to the command rather than creating a lot of conditional logic.