Environment variables and CI on

(Alexey Vinokurov) #1

Is it possible to setup environment variables while building project and how to access them from code? I’d like to use gitlab’s variables while building/deploying my project and substitute path to the local resources when I debug application on my end.

(Valentin Lemière) #2

No idea how to setup env var on gitlab, should be in the project settings or something like that.

For using those in your code it’s:

var value : String = Sys.getEnv("name");

You also have to modify and to get them all.

(Alexey Vinokurov) #3

I can’t read environment variables because my target is js and my question was about compile time. Now I can pass any external variable value at compile time by -D option like:

haxe -D internal_var=$external_var

But after that I can’t get passed value in code. Macro haxe.macro.Context.definedValue("var_name") returns an error:

src/Main.hx:10: characters 12-43 : Class<haxe.macro.Context> has no field definedValue

This behavior the same in haxe v3.0.0 (gitlab’s haxe docker image) and with my local build haxe v4.0.0.
If I don’t place option -D there’s no compile time errors in code and of cause I can’t get value, just to check if variable set or unset.

(Rudy Ges) #4

You can use the Sys API in macros too.

This looks like you called haxe.macro.Context.definedValue("var_name") outside the macro context (since it’s in your Main.hx, you may just need to properly add #if macro around your macro)

(Kevin Leung) #5

You should call Sys.getEnv("name"); in your macro