Sending environment variables to builds triggered via API

#1

I was wondering if there was a way to push an environment variable to a build triggered by the API?

I’m looking to parameterise the browsers being used by our end to end tests by checking an environment variable value (don’t worry, no secrets!) and I was wondering if this could be sent as a part of the POST body?

#2

if you are using drone build restart <repo> <build> you can pass parameters using the -p flag, for example something like this:

drone build start -p key1=val1 -p key2=val2 <repo> <build>
#3

Hi Brad,

Not currently! We’re looking to build them using the /api/repos/:owner/:project/builds/latest endpoint as opposed to the CLI.

#4

the CLI uses the API under the covers. The variables are pretty much just passed as url query parameters when you make the API call. Reference code here:

#5

Note that this may only work with Drone 1.x or higher

#6

Hi Brad,

thanks for the extra info - so if I were to try to add something like BROWSER_SELECTION=primary to the /api/repos/:owner/:project/builds/latest endpoint, would it be as simple as /api/repos/:owner/:project/builds/latest?BROWSER_SELECTION=primary?

#7

yes, that should do it

#8

Absolutely fantastic! Thanks a lot :+1:

#9

although I do not think /latest works with this particular endpoint