Setting global agent environment URL variables

I’ve been trying to hook Drone up to a private Python repository so as to use it as a default for all ‘pip’ installs. According to the ‘pip’ docs, ‘pip’ will respect a PIP_INDEX_URL environment variable if set. So I’m tying to figure out how to set that variable for all builds.

The first way I found was using the DRONE_RUNNER_ENVIRON environment variable. Unfortunately, there’s a known issue (bug?) with the configuration library Drone uses. Putting a URL in the variable results in an error:

error="envconfig.Process: assigning RUNNER_DRONE_RUNNER_ENVIRON to Environ: converting ‘PIP_INDEX_URL:https://piprepo/’ to type map[string]string. details: invalid map item: “PIP_INDEX_URL:https://piprepo/

See https://github.com/kelseyhightower/envconfig/issues/84. They mention workarounds there, but it would have to be implemented in Drone.

I also came across DRONE_GLOBAL_ENVIRON, but it no longer seems available in 1.0+.

Are there any other options for setting global environment variables?

Thank you.

There’s also a potential fix here: https://github.com/kelseyhightower/envconfig/pull/133

As of Drone 1.0 the variable name is DRONE_RUNNER_ENVIRON

The workaround mentioned in that thread is using custom json decoder for the map. This would be a breaking change for our users and is therefore something we would prefer to avoid. With that being said, perhaps we could introduce DRONE_RUNNER_ENVIRON_FILE as a new variable that loads a set of environment variables from file? We could use https://github.com/joho/godotenv (existing dependency) which would not be subject to the same limitation as the envconfig library.

An environment file would be perfect. I would generally prefer that to DRONE_RUNNER_ENVIRON anyway. Putting multiple key/value pairs in a string is a little unwieldy once you get past 3 or so.

The latest build of the autoscaler support the following configuration parameter:

DRONE_AGENT_ENV_FILE=/path/to/env/file

This load an environment file using the godotenv library.

Fantastic! Thanks for the update.

Is there any other fixes for this? I don’t use autoscaler, so I can’t use DRONE_AGENT_ENV_FILE.

1 Like

This feature is not limited to the autoscaler. If you want to pass an environment file directly to the runner you can use the following setting:
https://docs.drone.io/runner/docker/configuration/reference/drone-runner-env-file/