Docker Community Forums

Share and learn in the Docker community.

Is it possible to set build time env vars per tag on a repository?

(Lizter) #1

In the build tab in a repository, one can specify different tags that should build.
Let’s say I have one tag mapping for releases, and one for the master branch.
I would like to set different env vars in build time for these tag mappings.
Eg., “” for the releases and “” for our master branch CI build.
Is this currently possible? If not, I would like to request this feature :slight_smile:

Env variables in building aren't set
(Lizter) #2

First of, the build time env vars are not working at all ref: Env variables in building aren't set

I managed to work around this problem by specifying multiple Dockerfiles for my different envs and defining ARG variables with values. In my build configuration under Tag Mappings I then point my different tags to the corresponding Dockerfile.

Right now I have two tag mappings on the master branch with different Dockerfiles for two different test builds. This means that on each pull request or push to master, two builds will trigger. That is somewhat intended as the images are different, but I would rather have one Dockerfile with ARG whitelist defines without values for all my builds, and then specify their values in Docker Cloud for each tag mapping. That way when build cache gets introduced, I don’t have duplicates for all my different builds and I don’t have to keep values for my variables in source control.

(Andrew) #3

We do this multiple ways with our projects.

1st way is we use Jenkins for building, and we specify the tag with that, which will load certain variables into the build based on the environment.

2nd way we have items configured in the stackfile for environment variables such as API addresses.

3rd way we have an environment variable with the if it is dev/stage/live and then in the script it will do different actions based on that variable.

We usually find one of these will do for setting environmental settings. We personally haven’t needed other setting for configuring them.

(Lizter) #4

I appreciate your answer with different suggestions and alternatives, but I am discussing build time variables in Docker Cloud explicitly.

  1. Introducing Jenkins in addition to Docker Cloud seems overly complicated, this is a Docker Cloud Forum after all, and build time environment variables are already in the UI. They just don’t do anything.

  2. Variables defined in the stack file are runtime variables. This issue regards build time variables, a feature in Docker Core.

  3. To figure out if it is dev/stage/live, i.e. switch on this in the code, you still have to provide this variable either through runtime or build time. Runtime variables work great for some things, and I use them frequently, but again, this issue regards build time.

I realize most people get away (or around) using runtime variables, but for my case, I would like the Docker Cloud repository build options to reflect Docker Core’s build time variables like the UI at least seems to be headed to.