# Env BUILDTIME not working

**URL:** <https://discuss.hashicorp.com/t/env-buildtime-not-working/15289>\
**Category:** Packer\
**Created:** [October 8, 2020, 1:07pm UTC](https://discuss.hashicorp.com/t/env-buildtime-not-working/15289 "2020-10-08T13:07:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![krasi-github](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/krasi-github/32/12551_2.png) [@krasi-github](https://discuss.hashicorp.com/u/krasi-github)\
**Post date:** [October 8, 2020, 1:07pm UTC](https://discuss.hashicorp.com/t/env-buildtime-not-working/15289/1 "2020-10-08T13:07:59Z")

</div>

Hi,

My Packer Template incudes the following two variables:

```
    "vm_name": "linux-ubuntu-18-base-tmpl",
    "buildtime": "{{env `BUILDTIME`}}"

```

In the “builders” section I have this:  
“vm\_name”: “{{ user `vm_name` }}-{{ user `buildtime` }}”

Running the the build process works fine, but my VM name remains without “buildtime”.  
Like this: linux-ubuntu-18-base-tmpl-

I’m using latest Packer version, and “type”: “vsphere-iso”

Am I missing something?

---

<div class="post-metadata">

**Author:** ![krasi-github](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/krasi-github/32/12551_2.png) [@krasi-github](https://discuss.hashicorp.com/u/krasi-github)\
**Post date:** [October 8, 2020, 1:13pm UTC](https://discuss.hashicorp.com/t/env-buildtime-not-working/15289/2 "2020-10-08T13:13:10Z")

</div>

the “builders” section is like this (not sure how the quotes got away:

```
        "vm_name": "{{ user `vm_name` }}-{{ user `buildtime` }}",
```

---

<div class="post-metadata">

**Author:** ![nywilken](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/nywilken/32/2500_2.png) [@nywilken](https://discuss.hashicorp.com/u/nywilken)\
**Post date:** [October 9, 2020, 2:34pm UTC](https://discuss.hashicorp.com/t/env-buildtime-not-working/15289/3 "2020-10-09T14:34:05Z")

</div>

> [@krasi-github](#):
>
> `vm_name`

Hi there @krasi-github it looks to me that Packer is not finding the environment variable BUILDTIME. So packer is processing the variable as an empty string.

Is the environment variable being persisted to the shell running Packer?

Depending on how the environment variable is being set you need to make sure that it is persisted so that it is available to other programs like Packer, by either using `export BUILDTIME=somevalue` on \*nix systems or `set BUILDTIME=somevalue` on Windows systems.

Alternatively if it is a one time env variable you can set it when you call Packer, for example:  
`BUILDTIME=somevalue packer build template.json`

Lastly, I would like to mention that Packer has a timestamp function that you could use if you are looking to randomize the vm\_name based off build times.

`“vm_name”: “{{ user vm_name }}-{{timestamp}}”`

---

<div class="post-metadata">

**Author:** ![krasi-github](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/krasi-github/32/12551_2.png) [@krasi-github](https://discuss.hashicorp.com/u/krasi-github)\
**Post date:** [October 11, 2020, 10:39pm UTC](https://discuss.hashicorp.com/t/env-buildtime-not-working/15289/4 "2020-10-11T22:39:20Z")

</div>

Thanks @nywilken, much appreciated.  
I think the timestamp function will do the job for me.
