# Environment Variables

## Shell environment

Environment variables which are available from the shell environment get passed into the command before execution.

{% code title=".hammerkit.yaml" %}

```yaml
tasks:
  example:
    envs:
      VERSION: $VERSION
    cmds:
      - echo $VERSION
```

{% endcode %}

{% hint style="info" %}
Each environment variable that is used, should be specified in the `envs` of the task. Hammerkit ensures that the environment variable is defined, otherwise will throw an error to prevent undesired behavior.
{% endhint %}

## .env file

Environment variables can be defined in the .env file. Those are recommended for secret values that should not be committed nor public.

{% code title=".env" %}

```
NPM_TOKEN=abc
```

{% endcode %}

{% code title=".hammerkit.yaml" %}

```yaml
tasks:
  example:
    envs:
      NPM_TOKEN: $NPM_TOKEN
    cmds:
      - npm publish
```

{% endcode %}

## Defined values in the build file

Environment variables can be defined in the build file itself. They can be defined for the entire build file or only for specific tasks.

{% code title=".hammerkit.yaml" %}

```yaml
envs:
  NODE_VERSION: 14.16.0
  
tasks:
  example:
    cmds:
      - echo $NODE_VERSION
      
  override_example:
    envs:
      NODE_VERSION: 14.0.0
    cmds:
      - echo $NODE_VERSION
```

{% endcode %}

{% hint style="warning" %}
The scope of the defined environment variables are fixed to the build file they are defined in. Neither [referenced](/hammerkit/build-file/references.md) nor [included](/hammerkit/build-file/includes.md) tasks will have access to those.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://no0dles.gitbook.io/hammerkit/build-file/environment-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
