Environment variables not available in init section of task


I defined some environment variables using the Gitpod settings page. Those variables seem to be only available in the “command” section of a task (.gitpod.yml), but not in the “init” section. Is this correct behavior? Or maybe it’s cause my workspace is prebuilt?

Background: I like to run some Django migrations during “init”. Unfortunately, those fail as my Django settings file needs some already set environment variables to work.

Best regards,

Hi Kai,

indeed, the user-specific environment variables are not available in the init task. The init task is executed in prebuilds. Leaking user-specific environment variables in a prebuild would be a security issue as other users could trigger prebuilds as well.

However, you could set your environment variables in your Dockerfile or .gitpod.yml file directly.


Hi, Cornelius. Thanks for the clarification.

Some little other things I noticed about environment variables (just to document it here for others):

  • The ENV environment variables that are defined in the Dockerfile can be overwritten by the ones in the Gitpod settings
  • PYTHONPATH can’t be set (neither in the Dockerfile nor in the Gitpod settings) as it is unset when the workspace ist starting (see Setting PYTHONPATH not working?)
1 Like