# Environment variables and CI on gitlab.com

**URL:** <https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276>\
**Category:** Haxe\
**Created:** [November 15, 2018, 8:40pm UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276 "2018-11-15T20:40:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![meps](https://avatars.discourse-cdn.com/v2/letter/m/fbc32d/32.png) [@meps](https://community.haxe.org/u/meps)\
**Post date:** [November 15, 2018, 8:40pm UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276/1 "2018-11-15T20:40:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [November 16, 2018, 9:54am UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276/2 "2018-11-16T09:54:15Z")

</div>

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:

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

```

[https://api.haxe.org/Sys.html#getEnv](https://api.haxe.org/Sys.html#getEnv)

You also have [Sys - Haxe 4.2.1 API](https://api.haxe.org/Sys.html#putEnv) to modify and [Sys - Haxe 4.2.1 API](https://api.haxe.org/Sys.html#environment) to get them all.

---

<div class="post-metadata">

**Author:** ![meps](https://avatars.discourse-cdn.com/v2/letter/m/fbc32d/32.png) [@meps](https://community.haxe.org/u/meps)\
**Post date:** [November 17, 2018, 8:24am UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276/3 "2018-11-17T08:24:29Z")

</div>

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")`](https://haxe.org/manual/lf-condition-compilation.html#working-with-compiler-flags) 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.

---

<div class="post-metadata">

**Author:** ![kLabz](https://community.haxe.org/user_avatar/community.haxe.org/klabz/32/225_2.png) [@kLabz](https://community.haxe.org/u/kLabz)\
**Post date:** [November 18, 2018, 9:07am UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276/4 "2018-11-18T09:07:39Z")

</div>

> [@meps](#):
>
> I can’t read environment variables because my target is js and my question was about compile time.

You can use the Sys API in macros too.

> [@meps](#):
>
> src/Main.hx:10: characters 12-43 : Class\<haxe.macro.Context\> has no field definedValue

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)

---

<div class="post-metadata">

**Author:** ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)\
**Post date:** [November 26, 2018, 9:29am UTC](https://community.haxe.org/t/environment-variables-and-ci-on-gitlab-com/1276/5 "2018-11-26T09:29:46Z")

</div>

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