Plugin inputs as array

I’m trying to write a plugin that accepts an input that’s an array of strings.

I know I can express an array of string with JSON-Schema, but what will buildkite do with it? How will it get turned into a bash variable?

Thanks!

Hi @ianwremmel!

That’s a good question!
Arrays are a bit tricky and they are expanded into variables named like:

BUILDKITE_PLUGIN_SOMETHING_PATHS_0=…
BUILDKITE_PLUGIN_SOMETHING_PATHS_1=…

The docker plugin uses a function to read these into a bash array, for example:

You can find the full value, as it was in the original YAML, inside the JSON in $BUILDKITE_PLUGINS.

Hope this helps!

Cheers,

perfect, thanks!

This has been really helpful! Thanks!

To show my gratitude I’d like to add an example of how to test the array property using BATS:


@test "Array property check" {
    export BUILDKITE_PLUGIN_PIPELINER_JEDIS_0="Luke Skywalker"
    export BUILDKITE_PLUGIN_PIPELINER_JEDIS_1="Obi-Wan Kenobi"

    run "$PWD/hooks/command"
    assert_success
}

1 Like

This is great! Thanks for sharing! :hugs: