Set env vars on `drone exec --local`

Hi all.

I’m attempting to verify that the following use case is not possible (and request that it be added it if not :slight_smile:)

I wish to do something like:

$ drone exec -e ENV_VAR=value --local

and have ENV_VAR be set as an environment variable across all build steps in a .drone.yml pipeline.

My use case:
Certain environment variables are only available on our Drone server. These variables are integral to running the build successfully. For example, this is how we store service account credentials to various other systems. Without said env vars, the build will always fail, leaving us to to repeatedly push (or :scream: force push) new commits just to debug what’s wrong with our .drone.yml.

So my questions:

  1. Is this not possible? I’ve looked around but fear I may have missed something.
  2. Is there a better (currently functioning) way to get what I’m after?
  3. (if no to both :point_up:) Could this be integrated into a future release?

Cheers,
– jam

Is this not possible? I’ve looked around but fear I may have missed something.

-e is not currently supported

Is there a better (currently functioning) way to get what I’m after?

Unfortunately I do not think so

Could this be integrated into a future release?

Absolutely. Adding environment variables to the pipeline should be a relatively simple change. It will require a few minor modifications, which I tried to summarize below with some sample code:

envs := map[string]string{}
for _, env := range c.StringSlice("e") { // get -e KEY=VALUE variables
  envs = append(envs, strings.Splitn(env, "=", 2)
}

And then we pass the map to build runner like this:

	// compiles the yaml file
	compiled := compiler.New(
		compiler.WithEscalated(
			c.StringSlice("privileged")...,
		),
+		compiler.WithEnviron(envs...),
		compiler.WithVolumes(volumes...),
		compiler.WithWorkspace(
			c.String("workspace-base"),
			c.String("workspace-path"),
		),

If you are willing to open an issue for tracking, we can plan to include in the next release. If this is a high-priority item and you want to submit a PR, I am happy to get that expedited and merged for you.

Cheers

Awesome! Thanks for the quick reply :slight_smile:

I’ve opened a Github issue, here:

Set env vars on `drone exec --local` · Issue #2325 · harness/gitness · GitHub

I assume this conversation/thread will move there?