Sending environment variables to builds triggered via API

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?

1 Like

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>

Hi Brad,

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

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:

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

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?

yes, that should do it

Absolutely fantastic! Thanks a lot :+1:

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

I am sending params via the API and I confirmed that the param is present in the response body for the request. However, I am not seeing the param as an environment variables in the pipeline. How would I access this parameter?

My goal is to use this value as input to filter my test suite.

Same issue here:

curl -X POST -H "Authorization: Bearer xxxxxxx"

In the reply I get:

I tried to put ${job_template_name} in my .drone.yml file but nothing get passed.

Sorry was doing something wrong it actually works.

How did you get the params on the pipeline?

params are passed to pipeline steps as environment variables. Use env in your commands section to dump environment variables to verify.

- env
1 Like

Perfect, got it working now. Drone is very good bro

For me it was a stupid issue. I was running docker in docker, so in one of my steps, I had

docker run --rm -it acme:latest test

I had to also pass the environment variables that are injected from drone to the running container

docker run --rm -it -e MY_PARAMETER acme:latest test